ij-macro-programming-workshop

Previous            Exercise            Next

Exercise 05.03 - Variables and pre- and post increment

Aim:

The pre-increment ++a incements the value of a before the expression containing a is evaluated, the post-increment a++ first increments a and then evaluates the containing expression.

Look at the code below. What will be the values of a, b, c and d? Print the values of a, b, c and d to verify your answer.


a = 5;
b = a++ + 3;
c = 5;
d = ++c + 3;

Your code starts after this line

print("b:", b, "a:", a);
print("d:", d, "c:", c);
> b: 8 a: 6
> d: 9 c: 6

Your code ends before this line

Previous            Exercise            Next