C

Chandani • 9.82K Points
Tutor III

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\0
  • (D) Error

Explanation by: Chandani
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.


Question analytics