Correct Answer : A

Execution of program starts from `main`

. Inside `main`

are 2 integer variables declared called `n`

and `sum`

and are initialized to `0`

. The next statement is a `while`

loop with condition `n <= 6`

. As long as this condition is satisfied `while`

loop is executed.

Iteration 1: `sum += n++`

. This changes the value of `sum`

as `sum = sum + n++ = 0 + 0 = 0`

. So `sum`

becomes `0`

. The value of `n`

which is incremented is reflected for next usage. Then the value of `sum`

is printed using display statement.

Iteration 2: `sum += n++`

. This changes the value of `sum`

as `sum = sum + n++ = 0 + 1 = 1`

. So `sum`

becomes `1`

. The value of `n`

which is incremented is reflected for next usage. Then the value of `sum`

is printed using display statement.

Similarly the other iterations will get executed. When `n`

reaches `6`

and `n++`

occurs inside the loop sum will be `21 (= 0 + 1 + 2 + 3 + 4 + 5 + 6)`

. Then as `n`

becomes `7`

, loop terminates.

Now as `n`

became `0`

, the condition in `while`

returns `false`

, so `while`

loop terminates.