A

Admin • 833K Points
Coach

Q. What will be the output of the following C code? (If the input is "Hello world")

Code:
#include <stdio.h>

int main()
{
char str[30];

scanf("%s", str);
printf("%s", str);

return 0;
}
  • (A) Hello world
  • (B) Hello
  • (C) Hello world
  • (D) Error
  • Correct Answer - Option(B)
  • Views: 29
  • Filed under category C Programming
  • Hashtags:

Explanation by: Admin

When we read a string using the scanf() function, the input is terminated by the whitespace. Here, the input is "Hello world", so only "Hello" will be stored to str. Thus, the output will be "Hello".

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.