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
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
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)
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
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
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.
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
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
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.
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
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?
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
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
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
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.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos
- Buy Computer Science Books
- Practice BCA MCQs
- Practice Computer Science MCQs