Question 132

What is the output? int f(int n) {

What is the output? int f(int n) { return n == 0 ? 0 : n + f(n - 1); } printf("%d", f(4));
  1. A4
  2. B10
  3. C24
  4. D9
Show answerHide answer

Correct answer: (B) 10

Explanation

4 + 3 + 2 + 1 + 0 = 10.

From DSSSB TGT Computer Science Full Mock Test 4

This is question 132 of DSSSB TGT Computer Science Full Mock Test 4. 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.