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.

advertisement

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.
advertisement

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: d
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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & 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, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.