What is the output of the following program?
#include <stdio.h>
int main()
{
int var;
var = 1;
var = 2;
/* var = 3; */
print("%d", var);
return 0;
}
Explanation & Hints:
The output of the provided C program will be 2. Here’s a step-by-step explanation:
int var; declares an integer variable named var .
var = 1; sets the value of var to 1.
var = 2; then changes the value of var to 2.
/* var = 3; */ is commented out and thus has no effect on the program’s execution.
print("%d", var); should be printf("%d", var); to correctly compile in C. Assuming this is a typo and should be printf , it will print the current value of var , which is 2.
Therefore, the correct output, assuming the typo is corrected to printf , is 2. |
For more Questions and Answers: