A

Admin • 828.03K Points
Coach

Q. What is the output of the following C program?

Code:
#include <stdio.h>

int main()
{
printf("Hello World! %d
", x);
return 0;
}
  • (A) Hello World! x;
  • (B) Hello World! followed by a random value
  • (C) Compilation error
  • (D) Hello World!
  • Correct Answer - Option(C)
  • Views: 15
  • Filed under category C Programming
  • Hashtags:

Explanation by: Admin
This results in an error because the variable x is used without prior declaration. The output is as follows:

$gcc prog1.c
pgm1.c: In function ‘main’:
pgm1.c:4: error: ‘x’ undeclared (first use in this function)
pgm1.c:4: error: (Each undeclared identifier is reported only once
pgm1.c:4: error: for each function it appears in.)

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.