Multiple choice

What will be the value of sum after the following program is executed? main() { int sum, index; sum = 1; index = 9; do { index = index - 1; sum = 2*sum; } while(index >9);

  1. 1

  2. 2

  3. 9

  4. 0.5

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

The do-while loop executes at least once. Inside, index becomes 8 and sum becomes 2. The condition (index > 9) is checked, which is (8 > 9), so the loop terminates.