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.

1.

What will be the output of the program ?

 #include int main() { char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"}; int i; char *t; t = names[3]; names[3] = names[4]; names[4] = t; for(i=0; i<=4; i++) printf("%s,", names[i]); return 0; }

A. Suresh, Siva, Sona, Baiju, Ritu
B. Suresh, Siva, Sona, Ritu, Baiju
C. Suresh, Siva, Baiju, Sona, Ritu
D. Suresh, Siva, Ritu, Sona, Baiju
Answer» C. Suresh, Siva, Baiju, Sona, Ritu
2.

What will be the output of the program ?

 #include #include int main() { char str[] = "India 0 BIX 0"; printf("%d n", strlen(str)); return 0; }

A. 10
B. 6
C. 5
D. 11
Answer» D. 11
3.

What will be the output of the program ?

 #include int main() { char str[7] = "IndiaBIX"; printf("%s n", str); return 0; }

A. Error
B. IndiaBIX
C. Cannot predict
D.
Answer» D.
4.

What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?

 #include int main() { void fun(); fun(); printf(" n"); return 0; } void fun() { char c; if((c = getchar())!= ' n') fun(); printf("%c", c); }

A. abc abc
B. bca
C. Infinite loop
D. cba
Answer» E.
5.

What will be the output of the program ?

 #include int main() { printf("India", "BIX n"); return 0; }

A. Error
B. India BIX
C. India
D. BIX
Answer» D. BIX
6.

What will be the output of the program ?

 #include #include int main() { char str[] = "India 0 BIX 0"; printf("%s n", str); return 0; }

A. BIX
B. India
C. India BIX
D. India 0BIX
Answer» C. India BIX
7.

What will be the output of the program ?

 #include #include int main() { printf("%d n", strlen("123456")); return 0; }

A. 6
B. 12
C. 7
D. 2
Answer» B. 12
8.

What will be the output of the program ?

 #include int main() { printf(5+"Good Morning n"); return 0; }

A. Good Morning
B. Good
C. M
D. Morning
Answer» E.
9.

What will be the output of the program ?

 #include int main() { char p[] = "%d n"; p[1] = 'c'; printf(p, 65); return 0; }

A. A
B. a
C. c
D. 65
Answer» B. a
10.

What will be the output of the program ?

 #include #include int main() { char str1[20] = "Hello", str2[20] = " World"; printf("%s n", strcpy(str2, strcat(str1, str2))); return 0; }

A. Hello
B. World
C. Hello World
D. WorldHello
Answer» D. WorldHello
11.

What is the output of following program?

 # include  int main() { char str1[] = "GeeksQuiz"; char str2[] = {'G', 'e', 'e', 'k', 's', 'Q', 'u', 'i', 'z'}; int n1 = sizeof(str1)/sizeof(str1[0]); int n2 = sizeof(str2)/sizeof(str2[0]); printf("n1 = %d, n2 = %d", n1, n2); return 0; } 

A. n1 = 10, n2 = 9
B. n1 = 10, n2 = 10
C. n1 = 9, n2 = 9
D. n1 = 9, n2 = 10
Answer» B. n1 = 10, n2 = 10
12.

What will be the output of the program ?

 #include #include int main() { char str1[5], str2[5]; int i; gets(str1); gets(str2); i = strcmp(str1, str2); printf("%d n", i); return 0; }

A. Unpredictable integer value
B. -1
C. Error
Answer» B. -1
13.

What will be the output of the program ?

 #include int main() { int i; char a[] = " 0"; if(printf("%s", a)) printf("The string is not empty n"); else printf("The string is empty n"); return 0; }

A. The string is not empty
B. The string is empty
C. No output
Answer» C. No output
14.

If the size of pointer is 4 bytes then What will be the output of the program ?

 #include int main() { char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"}; printf("%d, %d", sizeof(str), strlen(str[0])); return 0; }

A. 22, 4
B. 25, 5
C. 24, 5
D. 20, 2
Answer» D. 20, 2
15.

What will be the output of the program (Turbo C in 16 bit platform DOS) ?

 #include #include int main() { char *str1 = "India"; char *str2 = "BIX"; char *str3; str3 = strcat(str1, str2); printf("%s %s n", str3, str1); return 0; }

A. IndiaBIX India
B. IndiaBIX IndiaBIX
C. India India
D. Error
Answer» C. India India
16.

What will be the output of the program ?

 #include #include int main() { char sentence[80]; int i; printf("Enter a line of text n"); gets(sentence); for(i=strlen(sentence)-1; i >=0; i--) putchar(sentence[i]); return 0; }

A. The sentence will get printed in same order as it entered
B. The sentence will get printed in reverse order
C. Half of the sentence will get printed
D. None of above
Answer» C. Half of the sentence will get printed
17.

What will be the output of the program ?

 #include int main() { printf(5+"IndiaBIX n"); return 0; }

A. Error
B. IndiaBIX
C. BIX
D. None of above
Answer» D. None of above
18.

What will be the output of the program ?

 #include int main() { char str[] = "Nagpur"; str[0]='K'; printf("%s, ", str); str = "Kanpur"; printf("%s", str+1); return 0; }

A. Kagpur, Kanpur
B. Nagpur, Kanpur
C. Kagpur, anpur
D. Error
Answer» E.
19.

What will be the output of the program ?

 #include int main() { char str = "IndiaBIX"; printf("%s n", str); return 0; }

A. Error
B. IndiaBIX
C. Base address of str
D. No output
Answer» B. IndiaBIX
20.

What will be the output of the program ?

 #include int main() { char str[25] = "IndiaBIX"; printf("%s n", &str+2); return 0; }

A. Garbage value
B. Error
C. No output
D. diaBIX
Answer» B. Error
21.

What will be the output of the program ?

 #include int main() { char str1[] = "Hello"; char str2[10]; char *t, *s; s = str1; t = str2; while(*t=*s) *t++ = *s++; printf("%s n", str2); return 0; }

A. Hello
B. HelloHello
C. No output
D. ello
Answer» B. HelloHello
22.

What will be the output of the program ?

 #include int main() { char str[] = "India 0BIX 0"; printf("%d n", sizeof(str)); return 0; }

A. 10
B. 6
C. 5
D. 11
Answer» E.
23.

What will be the output of the program ?

 #include int main() { static char mess[6][30] = {"Don't walk in front of me...", "I may not follow;", "Don't walk behind me...", "Just walk beside me...", "And be my friend." }; printf("%c, %c n", *(mess[2]+9), *(*(mess+2)+9)); return 0; }

A. t, t
B. k, k
C. n, k
D. m, f
Answer» C. n, k
24.

What will be the output of the program ?

 #include int main() { int i; char a[] = " 0"; if(printf("%s", a)) printf("The string is empty n"); else printf("The string is not empty n"); return 0; }

A. The string is empty
B. The string is not empty
C. No output
Answer» C. No output
25.

If char=1, int=4, and float=4 bytes size, What will be the output of the program ?

 #include int main() { char ch = 'A'; printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f)); return 0; }

A. 1, 2, 4
B. 1, 4, 4
C. 2, 2, 4
D. 2, 4, 8
Answer» C. 2, 2, 4
26.

What will be the output of the program in 16-bit platform (Turbo C under DOS) ?

 #include int main() { printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0)); return 0; }

A. 8, 1, 4
B. 4, 2, 8
C. 4, 2, 4
D. 10, 3, 4
Answer» C. 4, 2, 4
27.

What will be the output of the following C code?

 const char pla[] = "string1"; const char src[] = "string2"; printf("Before memmove place= %s, src = %s n", pla, src); memmove(pla, src, 7); printf("After memmove place = %s, src = %s n", pla, src);

A. Before memmove place= string1, src = string2 After memmove place = string2, src = string2
B. Before memmove place = string2, src = string2 After memmove place= string1, src = string2
C. Before memmove place = string2, src = string1 After memmove place= string2, src =string2
D. Before memmove place= string1, src = string2 After memmove place=string1, src = string1
Answer» B. Before memmove place = string2, src = string2 After memmove place= string1, src = string2
28.

Assume that a character takes 1 byte. Output of following program?

 #include int main() { char str[20] = "GeeksQuiz"; printf ("%d", sizeof(str)); return 0; } 

A. 9
B. 10
C. 20
D. Garbage Value
Answer» D. Garbage Value
29.

Output of following program

 #include  int fun(char *p) { if (p == NULL || *p == ' 0') return 0; int current = 1, i = 1; while (*(p+current)) { if (p[current] != p[current-1]) { p[i] = p[current]; i++; } current++; } *(p+i)=' 0'; return i; } int main() { char str[] = "geeksskeeg"; fun(str); puts(str); return 0; } 

A. gekskeg
B. geeksskeeg
C. geeks
D. Garbage Values
Answer» B. geeksskeeg
30.

Predict the output of the following program:

 #include  int main() { char str[] = "%d %c", arr[] = "GeeksQuiz"; printf(str, 0[arr], 2[arr + 3]); return 0; } 

A. G Q
B. 71 81
C. 71 Q
D. Compile-time error
Answer» D. Compile-time error
31.

Output?

 int main() { char a[2][3][3] = {'g','e','e','k','s','q','u','i','z'}; printf("%s ", **a); return 0; } 

A. Compiler Error
B. geeksquiz followed by garbage characters
C. geeksquiz
D. Runtime Error
Answer» D. Runtime Error
32.

 #include  void my_toUpper(char* str, int index) { *(str + index) &= ~32; } int main() { char* arr = "geeksquiz"; my_toUpper(arr, 0); my_toUpper(arr, 5); printf("%s", arr); return 0; } 

A. GeeksQuiz
B. geeksquiz
C. Compiler dependent
Answer» D.
33.

In below program, what would you put in place of ? to print Quiz ?

 #include  int main() { char arr[] = "GeeksQuiz"; printf("%s", ?); return 0; } 

A. arr
B. (arr+5)
C. (arr+4)
D. Not possible
Answer» C. (arr+4)
34.

What does the following fragment of C-program print?

 char c[] = "GATE2011"; char *p =c; printf("%s", p + p[3] - p[1]) ; 

A. GATE2011
B. E2011
C. 2011
D. 011
Answer» D. 011
35.

Predict the output?

 #include  int fun(char *str1) { char *str2 = str1; while(*++str1); return (str1-str2); } int main() { char *str = "GeeksQuiz"; printf("%d", fun(str)); return 0; } 

A. 10
B. 9
C. 8
D. Random Number
Answer» C. 8
36.

What is the output of following program?

 #include void swap(char *str1, char *str2) { char *temp = str1; str1 = str2; str2 = temp; } int main() { char *str1 = "Geeks"; char *str2 = "Quiz"; swap(str1, str2); printf("str1 is %s, str2 is %s", str1, str2); return 0; } 

A. str1 is Quiz, str2 is Geeks
B. str1 is Geeks, str2 is Quiz
C.
D. D.
E.
Answer» C.
37.

NULL is the macro defined in the header string. h.

A. true
B. false
Answer» B. false
38.

Which of the following is the variable type defined in header string. h?

A. sizet
B. size
C. size_t
D. size-t
Answer» D. size-t
39.

What is the function of strcoll()?

A. compares the string, result is dependent on the LC_COLLATE
B. copies the string, result is dependent on the LC_COLLATE
C. compares the string, result is not dependent on the LC_COLLATE
D. copies the string, result is not dependent on the LC_COLLATE
Answer» B. copies the string, result is dependent on the LC_COLLATE
40.

The ______ function appends not more than n characters.

A. strcat()
B. strcon()
C. strncat()
D. memcat()
Answer» D. memcat()
41.

What is the prototype of strcoll() function?

A. int strcoll(const char *s1,const char *s2)
B. int strcoll(const char *s1)
C. int strcoll(const *s1,const *s2)
D. int strcoll(const *s1)
Answer» B. int strcoll(const char *s1)
42.

What will strcmp() function do?

A. compares the first n characters of the object
B. compares the string
C. undefined function
D. copies the string
Answer» C. undefined function
43.

Which function will you choose to join two words?

A. strcpy()
B. strcat()
C. strncon()
D. memcon()
Answer» C. strncon()
44.

Which among the following is Copying function?

A. memcpy()
B. strcopy()
C. memcopy()
D. strxcpy()
Answer» B. strcopy()
45.

 #include  int main() { char *str1 = "GeeksQuiz"; char str2[] = "GeeksQuiz"; printf("sizeof(str1) = %d, sizeof(str2) = %d", sizeof(str1), sizeof(str2)); return 0; } 

A. sizeof(str1) = 10, sizeof(str2) = 10
B. sizeof(str1) = 4, sizeof(str2) = 10
C. sizeof(str1) = 4, sizeof(str2) = 4
D. sizeof(str1) = 10, sizeof(str2) = 4
Answer» C. sizeof(str1) = 4, sizeof(str2) = 4
46.

Functions whose names begin with strn

A. manipulates sequences of arbitrary characters
B. manipulates null-terminated sequences of characters
C. manipulates sequence of non null characters.
D. returns a pointer to the token
Answer» D. returns a pointer to the token
47.

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
Answer» E.
48.

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
Answer» C. 4
49.

Which of the following is the right syntax to copy n characters from the object pointed to by s2 into the object pointed to by s1?

A. void *memcpy(void *s1,const void *s2,size_t n);
B. void *memcpy(void *s2, const void *s1, size_t n);
C. void memcpy(void *s1,const void *s2, size_t n);
D. void memcpy(void *s2,const void *s1,size_t n);
Answer» B. void *memcpy(void *s2, const void *s1, size_t n);
50.

What is the function of void *memset(s, c, n)?

A. places character s into first n characters of c, return c
B. places character c into first n characters of s, return s
C. places character s into first n characters of c, return s
D. places character c into first n character of s, return c
Answer» C. places character s into first n characters of c, return s