Question 10Asked in DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 2

What is the output of the code written in C? void main()

What is the output of the code written in C? void main() { int k, val = 1; k = ++val * ++val; printf("%d", k); }
  1. A1
  2. B4
  3. C9
  4. D16
Show answerHide answer

Correct answer: (C) 9

Explanation

Modifying val twice in one expression is undefined behaviour in C, but common compilers (e.g. GCC) apply both increments first, making val = 3, and then compute 3 * 3 = 9.

From DSSSB TGT Computer Science PYQ (Technical), 7 Aug 2021, Shift 2

This is question 10 of DSSSB TGT Computer Science PYQ (Technical), 7 Aug 2021, Shift 2. 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.