Question 58Asked in DSSSB TGT Computer Science (Technical), 12 Sep 2025, Shift 2 (1:00 PM)

What will be the output of the following C code? int main() {

What will be the output of the following C code? #include <stdio.h> int main() { int i; for (i = 1; i <= 10; i++) { if (++i % 2 == 0) printf("%d ", i); } return 0; }
  1. A1 2 3 4 5 6 7 8 9 10
  2. B2 4 6 8 10
  3. C1 3 5 7 9
  4. D2 4 6 8
Show answerHide answer

Correct answer: (B) 2 4 6 8 10

Explanation

++i inside the if makes i even each time it is tested: i goes 1 to 2 (printed), then the loop's i++ makes 3, ++i makes 4 (printed), and so on up to 10. Then i becomes 11 and the loop stops, so 2 4 6 8 10 is printed.

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

This is question 58 of DSSSB TGT Computer Science PYQ (Technical), 12 Sep 2025, Shift 2 (1:00 PM). 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.