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\n", y);
return 0;
}
β
Correct Answer: (A)
Compilation error
Explanation: 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