254 Part III
Answer 87: The prefix version of
++
returns the number after incrementing.
Thus
++++i;
tells C++ increment
i
, returns the result, then increments the variable
i
again.
The postfix version of
++
(i++)
returns a copy of the variable, then incre-
ments it.
So
++++i
1. Tells C++ to make a copy of
i
(call it
tmp_1
)
2. Increments
i
3. Does the rest of the work on
tmp_1
4. Makes a copy of
tmp_1
(call it
tmp_2
)
5. Increments
tmp_2
6. Returns
tmp_1
as the value of the expression
NOTE C++ won’t let you get away with
++++
on integers. Only with some added class silliness can
you get away with it.
Avoidance 31: Use
++
and
--
singly.
Answer 88: The problem is the macro:
#define SQR(x) ((x) * (x))
when called with
SQR(++number)
This expands to
((++number) * ...