Question 46Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 1 (9:00 AM)

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; }
  1. Ax = 11, y = 41
  2. Bx = 10, y = 41
  3. Cx = 10, y = 20
  4. Dx = 11, y = 20
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.

From DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 1 (9:00 AM)

This is question 46 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 1 (9:00 AM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.