PART I
C h a p t e r 4 :
O p e r a t o r s
65
PART IPART I
Understand, however, that in the increment or decrement forms,
x
is evaluated only once,
not twice. This can improve efficiency in some cases.
Both the increment and decrement operators can either precede (prefix) or follow
(postfix) the operand. For example
x = x + 1;
can be written as
++x; // prefix form
or as
x++; // postfix form
In the foregoing example, there is no difference whether the increment is applied as a
prefix or a postfix. However, when an increment or decrement is used as part of a larger
expression, there is an important difference. When an increment or decrement operator
precedes
its operand, the result of the operation is the value of the operand
after
the increment.
If the operator
follows
its operand, the result of the operation is the value of the operand
before
the increment. Consider the following:
x = 10;
y = ++x;
In this case,
Do'stlaringiz bilan baham: |