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;
}
β
Correct Answer: (B)
Hello
Explanation: 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".