Knowee
Questions
Features
Study Tools

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

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be 20.

Here's the step by step explanation:

  1. The program starts with the inclusion of the standard input/output library in C, #include<stdio.h>.

  2. Then, a global variable X is declared and initialized with the value 40.

  3. The main() function is defined. This is the entry point of the program.

  4. Inside the main() function, a local variable X is declared and initialized with the value 20. This local variable X is different from the global variable X. The scope of this local X is within the main() function only.

  5. The printf() function is called to print the value of X. Since the local variable X is in scope, its value (20) is printed.

  6. The main() function returns 0, indicating successful termination of the program.

So, the correct answer is 20.

This problem has been solved

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

1/4

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.