Multiple choice

void main() {
  int i = 4, x;
  x = ++i + ++i + ++i;
  printf("%d", x);
}

What will be the output of the above code?

  1. 20

  2. 21

  3. 18

  4. 19

  5. 22

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The ++ operator is the pre fix increment operator. The pre increment operator first increments the variable up to break point then starts assigning the final value to all variable. Therefore the statement x=++i + ++i + ++i; will translate into x=5+6+7; after all the increments are finished, x will have the value 7 since, that is the last value after the statement. Now the final result will be x=7+7+7 that is 21.