R

Rudra Pratap Singh • 3.39K Points
Extraordinary

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

Code:
#include <stdio.h>

int main()
{
   printf("Hello World! %d \n", x);
   return 0;
}
  • (A) Hello World! x;
  • (B) Hello World! followed by a random value
  • (C) Compilation error
  • (D) Hello World!

Explanation by: Rudra Pratap Singh
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.


Question analytics