logo
  • Home
  • Rank
  • Tests
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

C Multiple Choice Questions | MCQs | Quiz

C Programming Interview Questions and Answers
Practice C Programming questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Variable Names - 1
•   Variable Names - 2
•   Data Types
•   Data Sizes
•   Constants - 1
•   Constants - 2
•   Declarations - 1
•   Declarations - 2
•   Arithmetic Operators - 1
•   Arithmetic Operators - 2
•   Relational Operators
•   Logical Operators
•   Type Conversions - 1
•   Type Conversions - 2
•   Increment Operators
•   Decrement Operators
•   Bitwise Operators - 1
•   Bitwise Operators - 2
•   Assigment Operators
•   Expressions
•   Conditional Expressions - 1
•   Conditional Expressions - 2
•   Operator Precedence - 1
•   Operator Precedence - 2
•   Order of Evaluation - 1
•   Order of Evaluation - 2
•   Associativity - 1
•   Associativity - 2
•   If Statements - 1
•   If Statements - 2
•   Switch Statements - 1
•   Switch Statements - 2
•   For Loops - 1
•   For Loops - 2
•   While Loops - 1
•   While Loops - 2
•   Break & Continue - 1
•   Break & Continue - 2
•   Goto & Labels - 1
•   Goto & Labels - 2
•   Functions Basics - 1
•   Function Basics - 2
•   Functions Return
•   Return Values
•   External Variables - 1
•   External Variables - 2
•   Variable Scope - 1
•   Variable Scope - 2
•   Static Variables - 1
•   Static Variables - 2
•   Register Variables - 1
•   Register Variables - 2
•   Automatic Variables - 1
•   Automatic Variables - 2
•   Preprocessor - 1
•   Preprocessor - 2
•   File Inclusion - 1
•   File Inclusion - 2
•   Macro Substitution - 1
•   Macro Substitution - 2
•   Conditional Inclusion - 1
•   Conditional Inclusion - 2
•   Pointers & Addresses - 1
•   Pointers & Addresses - 2
•   Function Arguments - 1
•   Pointers Arguments 2
•   Pointers & Arrays - 1
•   Pointers & Arrays - 2
•   Address Arithmetic - 1
•   Address Arithmetic - 2
•   Pointers/Functions - 1
•   Pointers/Functions - 2
•   Pointers to Pointers - 1
•   Pointers to Pointers - 2
•   Multidimensional Arrays - 1
•   Multidimensional Arrays - 2
•   Pointer Arrays Init - 1
•   Pointer Arrays Init - 2
•   Multi-dimensional Arrays - 1
•   Multi-dimensional Arrays - 2
•   Command Line Arguments1
•   Command Line Arguments2
•   Pointers to Functions - 1
•   Pointers to Functions - 2
•   Complicated Declarations-1
•   Complicated Declarations-2
•   Structures - 1
•   Structures - 2
•   Structures & Functions - 1
•   Structures & Functions - 2
•   Arrays of Structures - 1
•   Arrays of Structures - 2
•   Pointer to Structures - 1
•   Pointer to Structures - 2
•   Self-Referential Structures-1
•   Self-Referential Structures-2
•   Table Lookup - 1
•   Table Lookup - 2
•   Typedefs - 1
•   Typedefs - 2
•   Unions - 1
•   Unions - 2
•   Bit-fields - 1
•   Bit-fields - 2
•   Standard Input & Output - 1
•   Standard Input & Output - 2
•   Formatted Output - 1
•   Formatted Output - 2
•   Varargs - 1
•   Varargs - 2
•   Formatted Input - 1
•   Formatted Input - 1
•   File Access - 1
•   File Access - 2
•   Error Handling - 1
•   Error Handling - 2
•   Line Input & Output - 1
•   Line Input & Output - 2
•   String Operations - 1
•   String Operations - 2
•   Character Class - 1
•   Character Class - 2
•   Ungetc - 1
•   Ungetc - 2
•   Storage Management - 1
•   Storage Management - 2
•   Mathematical Functions - 1
•   Mathematical Functions - 2
•   Random Number - 1
•   Random Number - 2
•   printf - 1
•   printf - 2
•   scanf - 1
•   scanf - 2
•   File Operations - 1
•   File Operations - 2
•   Float Datatype - 1
•   Float Datatype - 2
•   Sizeof Keyword - 1
•   Sizeof Keyword - 2
•   Enums - 1
•   Enums - 2
•   Typedef
•   String Operations - 1
•   String Operations - 2
•   String Operations - 3
•   String Operations - 4
•   Character Handling - 1
•   Character Handling - 2
•   Error Handling
•   Mathematical Functions - 1
•   Mathematical Functions - 2
•   Mathematical Functions - 3
•   General Utilities - 1
•   General Utilities - 2
•   General Utilities - 3
•   General Utilities - 4
•   General Utilities - 5
•   General Utilities - 6
•   Diagnostics - 1
•   Diagnostics - 2
•   Variable Argument Lists
•   Localization
•   Non-Local Jumps - 1
•   Non-Local Jumps - 2
•   Signal Handling
•   Standard Definition
•   Date & Time Functions - 1
•   Date & Time Functions - 2
•   Date & Time Functions - 3
•   Defined Limits - 1
•   Defined Limits - 2
•   Dynamic Memory Allocation
•   Dangling Pointers - 1
•   Dangling Pointers - 2
•   Pragma
•   Stringizers
•   Preprocessor Directives - 1
•   Preprocessor Directives - 2
•   Token Concatenation
•   Inline
•   Endianness
•   Recursion
•   Signed Qualifier

C Tests

C Tests

Best Reference Books

C Programming Books
« Prev Page
Next Page »

C Questions and Answers – String Operations – 4

Posted on February 2, 2013 by Manish

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “String Operations – 4”.

1. What will be returned by given C code?

advertisement
size- t strlen(const char *s)
const char *sc;
for(sc = s; *sc!= ' \ O ' ; ++sc)
return(sc - s) ;

a) number of characters equal in sc
b) length of string s
c) doesn’t return any value
d) displays string s
View Answer

Answer: b
Explanation: The strlen() function is used to return the length of the string s.

2. The function strsp() is the complement of strcspn().
a) true
b) false
View Answer

Answer: a
Explanation: Both strcspn() and strpbrk() perform the same function. Only strspn() the return values differ. The function strspn() is the complement of strcspn() .

3. What will the following code do?

char * strrchr(const char *s, int c )
char ch = c;
char *sc;
for(sc = NULL; ; ++s)
if(*s == ch)
SC = 9;
i f (*s =='\O' )
return (( char *) s);

a) find last occurrence of c in char s[ ].
b) find first occurrence of c in char s[ ].
c) find the current location of c in char s[ ].
d) There is error in the given code
View Answer

Answer: a
Explanation:The strrchr() function locates the last occurrence of c (converted to a char) in the string pointed to by s. String contains null character as a terminating part of it.
advertisement

4. This function offers the quickest way to determine whether two character sequences of the same known length match character for the character up to and including any null character in both.
a) strcmp()
b) memcmp()
c) strncmp()
d) no such function
View Answer

Answer: c
Explanation: The strncmp() function is used to compare not more than n characters (characters that follow a null character are not compared) from the array pointed to by one, to the array pointed to by other.

5. What will be the output of the following C code?

char str1[15];
char str2[15];
int mat;
strcpy(str1, "abcdef");
strcpy(str2, "ABCDEF");
mat= strncmp(str1, str2, 4);
if(mat< 0)
printf("str1 is not greater than str2");
else if(mat> 0)
printf("str2 is is not greater than str1");
else
printf("both are equal");

a) str1 is not greater than str2
b) str2 is not greater than str1
c) both are equal
d) error in given code
View Answer

Answer: b
Explanation: The C library function int strncmp(const char *str1, const char *str2, size_t n) is used to compare at most the first n bytes of str1 and str2.

6. What will be the output of the following C code?

advertisement
void *memset(void *c, int c, size-t n) 
unsigned char ch = c;
unsigned char *su;
for (su = s; 0 < n; ++su, --n)
<br>
*su = ch;
<br>

a) store c throughout unsigned char s[n]
b) store c throughout signed char s[n]
c) find first occurrence of c in s[n]
d) find last occurrence of c in s[n]
View Answer

Answer: a
Explanation: This is the safe way to store the same value throughout a contiguous sequence of elements in a character array.

7. Use_______to determine the null-terminated message string that corresponds to the error code errcode.
a) strerror()
b) strstr()
c) strxfrm()
d) memset()
View Answer

Answer: a
Explanation: Use strerror (errcode) to determine the null-terminated message string that corresponds to the error code errcode.

8. What will be the output of the following C code?

const char str1[10]="Helloworld";
const char str2[10] = "world";
char *mat;
mat = strstr(str1, str2);
printf("The substring is:%s\n", mat);

a) The substring is:world
b) The substring is:Hello
c) The substring is:Helloworld
d) error in the code
View Answer

Answer: a
Explanation: The C library function char *strstr(const char *str1, const char *str2) is used to find the first occurrence of the substring str2 in the string str1.The terminating ‘\0’ characters are not compared.

9. void *memcpy(void *dest, const void *src, size_t n) What does the following code do?
a) copies n characters from src to dest
b) copies n character from dest to src
c) transform n character from dest to src
d) transform n character from src to dest
View Answer

Answer: a
Explanation: In the C library function memcpy() is used to copy n characters from memory area src to memory area dest.

10. What will the given C code do?

int memcmp(const void *str1, const void *str2, size_t n)

a) compares the first n bytes of str1 and str2
b) copies the first n bytes of str1 to str2
c) copies the first n bytes of str2 to str1
d) Invalid function
View Answer

Answer: a
Explanation: In the C library function int memcmp(const void *str1, const void *str2, size_t n)) is used to compare the first n bytes of memory area str1 and memory area str2.

Sanfoundry Global Education & Learning Series – C Programming Language.

C Practice Resources
C Mock Tests & Certification Test | 1000 C MCQs | 1000 C Programs | 1000 C Algorithms | Best C Books | C Internship
« Prev Page - C Questions and Answers – String Operations – 3
» Next Page - C Questions and Answers – Character Handling – 1

« C Questions and Answers – String Operations – 3
C Questions and Answers – Character Handling – 1 »
advertisement

Deep Dive @ Sanfoundry:

  1. C++ Questions and Answers
  2. Python Programming Examples
  3. C Tutorials
  4. C Programming Examples on Bitwise Operations
  5. C# Programming Examples on Strings
  6. Java Programming Examples on Set & String Problems & Algorithms
  7. C++ Programming Examples on Set & String Problems & Algorithms
  8. C Programming Examples on Strings
  9. C Programming Examples on Set & String Problems & Algorithms
  10. Java Programming Examples on String Handling
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.