prev up next   top/contents search

comp.lang.c FAQ list · Question 3.12b

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

A: Since the two forms differ only in the value yielded, they are entirely equivalent when only their side effect is needed. (However, the prefix form is preferred in C++.) Some people will tell you that in the old days one form was preferred over the other because it utilized a PDP-11 autoincrement addressing mode, but those people are confused. An autoincrement addressing mode can only help if a pointer variable is being incremented and indirected upon, as in

	register char c, *cp;
	c = *cp++;
See also question 3.3.

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

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North