1.4.17 Toán tử pre- và post- (2)

Look carefully at this program.

int i, j;

i = 4;

j = 2 * i++;

i = 2 * – – j;

Let’s trace its execution step by step.

  1. The ivariable is assigned the value of 4;
  2. We take the original value of i(4), multiply it by 2, assign the result (8) to j and eventually (post-)increment the i variable (it’s now equal to 5);
  3. We (pre-)decrement the value of j(it’s now equal to 7), this reduced value is taken and multiplied by 2, and the result (14) is assigned to the variable i.