A

Admin • 833K Points
Coach

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

Code:
#include <stdio.h>

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

Explanation by: Admin

Since y is already defined, redefinition causes an error. The output is as follows:
$gcc prog2.c
pgm2.c: In function ‘main’:
pgm2.c:5: error: redefinition of ‘y’
pgm2.c:4: note: previous definition of ‘y’ was here

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.