increment operator

Dan McMullen lcc.dan at UCLA-LOCUS.ARPA
Sat Jul 13 06:32:31 AEST 1985


having perused the discussion of 'i++' vs. 'i = i + 1' for a few weeks now, i
am reminded a little of the Light Beer commercial - 'Tastes great!' vs. 'Less
Filling'.  at any rate, to throw a new (or maybe old) worm on the pile, consider
the operation of incrementing a pointer:
	int *ip;

	ip++;
	  vs.
	ip = ip + 1;
this may be a case where the '++' construct is clearer.  any comments?

for myself, the '++' construct in general is more *intuitive* than the altern-
ative.  it denotes a *single* operation, whether on an interger or a pointer,
whereas 'i = i + 1' denotes two (or three if fetching the value of 'i' is
included.  this is a beneficial economy of thought as i read a program.

what is intuitive for me, however, may not be as intuitive for others, and the
discussion goes on.  thanks to all who contribute.  the exchange is both enjoy-
able and instructive for me.

dan



More information about the Comp.lang.c mailing list