Programmer's favourite expression

exercise No. 103

Q:

Consider the following code fragment:

int a = 6,
    b = 7,
    c = -3,
    result = 0;

result += ++a - b++ + --c;

Rewrite this code by decomposing the last line into several lines to make the code easier to understand.

Hint: After execution of your modified code all variable must have identical values with respect to the original code. In other words: Your modifications shall not alter the code's behaviour in any way.

A:

Incrementing ++a and decrementing --c happens prior to adding / subtracting their values to the variable result (prefix notation). The increment operation b-- in contrast happens after being being subtracted from variable result (postfix notation). The following code snippet is thus equivalent:

int a = 6,
    b = 7,
    c = -3,
    result = 0;

++a;
--c;
result += a - b + c; // or even: result = result + a - b + c;
b++;