Top

Discussion

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: A

The C library function char *strstr(const char *str1, const char *str2) is used to find the first occurrence of the substring str2 in the string str1.The terminating ‘\0’ characters are not compared.

No comment is present. Be the first to comment.
Loading…

Post your comment