What will be the output of the following program?#include<stdio.h> int X=40; int main() { int X=20; printf("%d", X); return 0; }Select one:400Error20
Question
What will be the output of the following program?#include<stdio.h> int X=40; int main() { int X=20; printf("%d", X); return 0; }Select one:400Error20
Solution
The output of the program will be 20.
Here's the step by step explanation:
-
The program starts with the inclusion of the standard input/output library in C,
#include<stdio.h>. -
Then, a global variable
Xis declared and initialized with the value 40. -
The
main()function is defined. This is the entry point of the program. -
Inside the
main()function, a local variableXis declared and initialized with the value 20. This local variableXis different from the global variableX. The scope of this localXis within themain()function only. -
The
printf()function is called to print the value ofX. Since the local variableXis in scope, its value (20) is printed. -
The
main()function returns 0, indicating successful termination of the program.
So, the correct answer is 20.
Similar Questions
What is the output of the following C Program?
What will be the output of the following code?
what will be the output of the c program?
What will be the output of the following C++ code?
What will be the output of the following program?Note: This question helps in clearing the AMCAT exam
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.