Explore topic-wise MCQs in Strings.

This section includes 93 Mcqs, each offering curated multiple-choice questions to sharpen your Strings knowledge and support exam preparation. Choose a topic below to get started.

51.

Which among the given options is the right explanation for the statement size_t strcspn(c, s)?

A. return length of prefix of s consisting of characters not in c
B. return length of prefix of s consisting of characters present in c
C. return length of prefix of c consisting of characters not in s
D. return length of prefix of c consisting of characters present in s
Answer» D. return length of prefix of c consisting of characters present in s
52.

The mem functions are meant for _______

A. returning a pointer to the token
B. manipulating objects as character arrays
C. returning a pointer for implemented-defined string
D. returning a pointer to first occurrence of string in another string
Answer» C. returning a pointer for implemented-defined string
53.

Which code from the given option return pointer to last occurrence of c in ch or NULL if not present?

A. char *strchr(ch, c)
B. char *strrchr(ch, c)
C. char *strncat(ch, c)
D. char *strcat(ch, c)
Answer» C. char *strncat(ch, c)
54.

What is the use of function char *strchr(ch, c)?

A. return pointer to first occurrence of ch in c or NULL if not present
B. return pointer to first occurrence of c in ch or NULL if not present
C. return pointer to first occurrence of ch in c or ignores if not present
D. return pointer to first occurrence of cin ch or ignores if not present
Answer» C. return pointer to first occurrence of ch in c or ignores if not present
55.

There are two groups of string functions defined in the header . What are they?

A. first group names beginning with str; second group names beginning with mem
B. first group names beginning with str; second group names beginning with is
C. first group names beginning with string; second group names beginning with mem
D. first group names beginning with str; second group names beginning with type
Answer» B. first group names beginning with str; second group names beginning with is
56.

Which among the given options compares atmost n characters of string ch to string s?

A. int strncmp(ch, s, n)
B. int strcmp(ch, s)
C. int strncmp(s, ch, n)
D. int strcmp(s, ch)
Answer» B. int strcmp(ch, s)
57.

What will be the output of the following C code?

 const char str1[]="ABCDEF1234567"; const char str2[] = "269"; len = strcspn(str1, str2); printf("First matching character is at %d n", len + 1);

A. First matching character is at 8
B. First matching character is at 7
C. First matching character is at 9
D. First matching character is at 12
Answer» B. First matching character is at 7
58.

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» B. false
59.

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» C. strspn()
60.

Which of the given function is used to return a pointer to the located character?

A. strrchr()
B. strxfrm()
C. memchar()
D. strchar()
Answer» E.
61.

Is there any function declared as strstr()?

A. true
B. false
Answer» B. false
62.

The______function returns a pointer to the first character of a token.

A. strstr()
B. strcpy()
C. strspn()
D. strtok()
Answer» E.
63.

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» B. char *strtok(char *s2,const char *s1);
64.

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» B. length of the transformed string, including the terminating null-character
65.

What does the following function returns void *memmove(void *s1,const void s2, size_t n);?

A. returns the value of s1
B. returns the value of s2
C. doesn t return any value
D. returns the value of s1 and s2
Answer» B. returns the value of s2
66.

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
Answer» B. copies n character from dest to src
67.

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> 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
Answer» C. both are equal
68.

Use_______to determine the null-terminated message string that corresponds to the error code errcode.

A. strerror()
B. strstr()
C. strxfrm()
D. memset()
Answer» B. strstr()
69.

What will be the output of the following C code?

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

A. store c throughout unsigned char s[n]
B. store c throughout signed char s[n]
C.
D. D.
Answer» B. store c throughout signed char s[n]
70.

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
Answer» B. The substring is:Hello
71.

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
Answer» D. no such function
72.

What will the following C 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
Answer» B. find first occurrence of c in char s[ ].
73.

The function strsp() is the complement of strcspn().

A. true
B. false
Answer» B. false
74.

What will be returned in the following C code?

 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
Answer» C. doesn t return any value
75.

The______ function returns the number of characters that are present before the terminating null character.

A. strlength()
B. strlen()
C. strlent()
D. strchr()
Answer» C. strlent()
76.

String operation such as strcat(s, t), strcmp(s, t), strcpy(s, t) and strlen(s) heavily rely upon.

A. Presence of NULL character
B. Presence of new-line character
C. Presence of any escape sequence
D. None of the mentioned
Answer» B. Presence of new-line character
77.

What type of return-type used in String operations?

A. void only
B. void and (char *) only
C. void and int only
D. void, int and (char *) only
Answer» E.
78.

What will be the output of the following C code?

 #include  int main() { char str[10] = "hello"; char *str1 = "world"; strncat(str, str1, 9); printf("%s", str); }

A. helloworld
B. Undefined behaviour
C. helloworl
D. hellowor
Answer» B. Undefined behaviour
79.

Strcat() function adds null character.

A. Only if there is space
B. Always
C. Depends on the standard
D. Depends on the compiler
Answer» C. Depends on the standard
80.

What will be the output of the following C code?

 #include  int main() { char str[11] = "hello"; char *str1 = "world"; strcat(str, str1); printf("%s %d", str, str[10]); }

A. helloworld 0
B. helloworld anyvalue
C. worldhello 0
D. Segmentation fault/code crash
Answer» B. helloworld anyvalue
81.

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
Answer» B. copies the first n bytes of str1 to str2
82.

What will be the output of the following C code?

 #include  int main() { char *str = "hello, world n"; printf("%d", strlen(str)); }

A. Compilation error
B. Undefined behaviour
C. 13
D. 11
Answer» D. 11
83.

What will be the output of the following C code?

 #include  int main() { char *str = "hello, world"; char str1[15] = "hello wo 9"; strcpy(str, str1); printf("%s", str1); }

A. Compilation error
B. Segmentation Fault
C. hello, world
D. hello, wo 9
Answer» C. hello, world
84.

What will be the output of the following C code?

 #include  #include  int main() { char *str = "hello, world"; char str1[9]; strncpy(str1, str, 9); printf("%s %d", str1, strlen(str1)); }

A. hello, world 11
B. hello, wor 9
C. Undefined behaviour
D. Compilation error
Answer» D. Compilation error
85.

What will be the output of the following C code?

 #include  int main() { char *str = "hello, world"; char *str1 = "hello, world"; if (strcmp(str, str1)) printf("equal"); else printf("unequal"); }

A. equal
B. unequal
C. Compilation error
D. Depends on the compiler
Answer» C. Compilation error
86.

What will be the output of the following C code?

 #include  int main() { char str[10] = "hello"; char *p = strrchr(str, 'l'); printf("%c n", *(++p)); }

A. l
B. o
C. e
D. Compilation error
Answer» C. e
87.

If the two strings are identical, then strcmp() function returns

A. -1
B. 1
C. Yes
Answer» A. -1
88.

Which of the following function compares 2 strings with case-insensitively?

A. strcmp(s, t)
B. strcmpcase(s, t)
C. strcasecmp(s, t)
D. strchr(s, t)
Answer» D. strchr(s, t)
89.

What will be the value of var for the following C statement?

 var = strcmp("Hello", "World");

A. -1
B. 1
C. strcmp has void return-type
Answer» B. 1
90.

Which pre-defined function returns a pointer to the last occurence of a character in a string?

A. strchr(s, c);
B. strrchr(s, c);
C. strlchr(s, c);
D. strfchr(s, c);
Answer» C. strlchr(s, c);
91.

What will be the output of the program ?

 #include int main() { static char s[25] = "The cocaine man"; int i=0; char ch; ch = s[++i]; printf("%c", ch); ch = s[i++]; printf("%c", ch); ch = i++[s]; printf("%c", ch); ch = ++i[s]; printf("%c", ch); return 0; }

A. hhe!
B. he c
C. The c
D. Hhec
Answer» B. he c
92.

What will be the output of the program ?

 #include #include int main() { static char s[] = "Hello!"; printf("%d n", *(s+strlen(s))); return 0; }

A. 8
B. 16
C. Error
Answer» A. 8
93.

What will be the output of the program ?

 #include #include int main() { static char str1[] = "dills"; static char str2[20]; static char str3[] = "Daffo"; int i; i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills"); printf("%d n", i); return 0; }

A. 1
B. 2
C. 4
Answer» A. 1