Question 3.12

If I'm not using the value of the expression, should I use i++ or ++i to increment a variable?


Since the two forms differ only in the value yielded, they are entirely equivalent when only their side effect is needed.

See also question 3.3.

References: K&R1 Sec. 2.8 p. 43
K&R2 Sec. 2.8 p. 47
ANSI Sec. 3.3.2.4, Sec. 3.3.3.1
ISO Sec. 6.3.2.4, Sec. 6.3.3.1
H&S Sec. 7.4.4 pp. 192-3, Sec. 7.5.8 pp. 199-200


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback