πŸ“Š C Programming
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;
}
  • (A) Compilation error
  • (B) Hello World! 4
  • (C) Hello World! 8000
  • (D) Hello World! followed by a random value
πŸ’¬ Discuss
βœ… 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

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

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
189
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Rudra Pratap Singh
Publisher
πŸ“ˆ
98%
Success Rate