C Questions and Answers – String Operations – 3

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

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. What is the return value of strxfrm()?
a) length of the transformed string, not including the terminating null-character
b) length of the transformed string, including the terminating null-character
c) display the transformed string, not including the terminating null character
d) display the transformed string, not including the terminating null-character
View Answer

Answer: a
Explanation: This function returns the length of the transformed string, not including the terminating null character.

2. Is there any function declared as strstr()?
a) true
b) false
View Answer

Answer: a
Explanation: This function returns a pointer to the first occurrence in s1 of any of the entire sequence of characters specified in s2, or a null pointer if the sequence is not present in s1.
char *strstr(const char *s1, const char *s2)
advertisement
advertisement

3. The C library function _________ breaks string s1 into a series of tokens using the delimiter s2.
a) char *strtok(char *s1,const char *s2);
b) char *strtok(char *s2,const char *s1);
c) char *strstr(char *s1,const char *s2);
d) char *strstr(char *s2,const char *s1);
View Answer

Answer: a
Explanation: The C library function char *strtok(char *s1, const char *s2) breaks string s1 into a series of tokens using the delimiter s2.

4. The______function returns a pointer to the first character of a token.
a) strstr()
b) strcpy()
c) strspn()
d) strtok()
View Answer

Answer: d
Explanation: The strtok() function returns a pointer to the first character of a token, if there is no token then a null pointer is returned.
Note: Join free Sanfoundry classes at Telegram or Youtube

5. which of the following function returns a pointer to the located string or a null pointer if string is not found.
a) strtok()
b) strstr()
c) strspn()
d) strrchr()
View Answer

Answer: b
Explanation: The strstr() function is used to return a pointer to the located string, or if string is not found a null pointer is returned.

6. Which of the given function is used to return a pointer to the located character?
a) strrchr()
b) strxfrm()
c) memchar()
d) strchar()
View Answer

Answer: d
Explanation: The strchr() function is used to return a pointer to the located character if character does not occur then a null pointer is returned.
advertisement

7. The strpbrk() function is used to return a pointer to the character, or a null pointer if no character from s2 occurs in s1.
a) true
b) false
View Answer

Answer: a
Explanation: char *strpbrk(const char *s1,const char *s2);
The first occurrence in the string s1 of any character from the string s2 is done by strpbrk().

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

advertisement
const char str1[] = "abcdef";
const char str2[] = "fgha";
char *mat;
mat= strpbrk(str1, str2);
if(mat)
printf("First matching character: %c\n", *mat);
else
printf("Character not found");

a) g
b) a
c) h
d) f
View Answer

Answer: b
Explanation: The strpbrk() function is used to locate the first occurrence in the string str1 of any character from the string str2.

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

char str1[] = "Helloworld ";
char str2[] = "Hello";
len = strspn(str1, str2);
printf("Length of initial segment matching %d\n", len );

a) 6
b) 5
c) 4
d) no match
View Answer

Answer: b
Explanation: The length of the maximum initial segment of the string str1 which consists entirely of characters from the string str2 is computed by strspn().

10. The______ function returns the number of characters that are present before the terminating null character.
a) strlength()
b) strlen()
c) strlent()
d) strchr()
View Answer

Answer: b
Explanation: The strlen() function is used to return the number of characters that are present before the terminating null character.size-t strlen(const char *s);The length of the string pointed to by s is computed by strlen().

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.