250+ TOP MCQs on String Operations and Answers

C Objective Questions on “String Operations – 3”.

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
Answer: a
Clarification: 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
Answer: a
Clarification: 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);
Answer: a
Clarification: 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()
Answer: d
Clarification: 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()
Answer: b
Clarification: 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()
Answer: d
Clarification: 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
Answer: a
Clarification: 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: %cn", *mat);
else
printf("Character not found");

a) g
b) a
c) h
d) f
Answer: d
Clarification: 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 %dn", len );

a) 6
b) 5
c) 4
d) no match
Answer: b
Clarification: 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()
Answer: b
Clarification: 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().

Leave a Reply

Your email address will not be published. Required fields are marked *