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

Code:
#include <stdio.h>

int main()
{
    int main = 9;
    printf("%d", main);
    return 0;
}
  • (A) This will cause a compile error
  • (B) This will cause a runtime error
  • (C) It will run without error and displays 9
  • (D) It goes into an infinite loop
πŸ’¬ Discuss
βœ… Correct Answer: (C) It will run without error and displays 9
Explanation: In a C program, you may encounter the same name of a function and the same name of a variable. The program will display:

$gcc prog3.c
$ a.out
9
Explanation by: Rudra Pratap Singh
In a C program, you may encounter the same name of a function and the same name of a variable. The program will display:

$gcc prog3.c
$ a.out
9

πŸ’¬ Discussion


πŸ“Š Question Analytics

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