What will be the output of the given C program? int main()
What will be the output of the given C program?
#include <stdio.h>
int main()
{
{
int x = 10, y = 20;
{
{
int y = 40;
x++;
y++;
}
printf("x = %d, y = %d\n", x, y);
}
}
return 0;
}
Show answerHide answer
Correct answer: (D) x = 11, y = 20
Explanation
The inner block declares a new y = 40, which shadows the outer y; y++ changes only that inner copy. x is not redeclared, so x++ changes the outer x to 11. The printf sees x = 11 and the outer y = 20.