difference between c++; and ++c;

M.T.Russell mtr at ukc.ac.uk
Tue Apr 9 06:46:43 AEST 1991


In article <1991Apr08.161444.10025 at cs.ruu.nl> hnridder at cs.ruu.nl (Ernst de Ridder) writes:
>[Why is ++i better than i++ when the value is unused]

Because it is a more direct expression of the desired operation.
Notionally we have:

   i++;	  "Save the current value of i, increment i then discard
	   the value just saved"

versus:

   ++i;   "Increment i then discard the resulting value"

Obviously most compilers will generate exactly the same code for
either case, but it is nice to express what you mean as directly as
possible.

Mark



More information about the Comp.std.c mailing list