Strings MCQ Questions and Answers

Home | C Language | Strings

In this section we provide lots of objective question of Strings

Page: 1/2

1) Which of the following function sets first n characters of a string to a given character?

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

3) How will you print \n on the screen?

4) The library function used to find the last occurrence of a character in a string is

5) Which of the following function is used to find the first occurrence of a given string in another string?

6) Which of the following function is more appropriate for reading in a multi-word string?

7) What is the output of this C code?

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

8) What is the output of this C code?

#include <stdio.h>
int main()
{
char *str = "hello";
char str1[5];
strcpy(str, str1);
printf("%s", str1);
}

9) What is the output of this C code?

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

10) What is the output of this C code?

#include <stdio.h>
int main()
{
char *str = "hello, world\n";
printf("%d", strlen(str));
}

Download MCQ PDF