Don't modify a variable more than once in a single statement

This tip submitted by Ganga R Jaiswal on 2011-09-29 14:30:37. It has been viewed 7761 times.
Rating of 5.5 with 32 votes



Don�t modify any variable more than once in a single statement:
You should not modify a variable more than once in a single statement. Compiler behavior is not defined by ANSI C for such scenario; it may produce different result on different compilers.

Example:

A = (b++) + (++b); //NOT OK: b has been modified twice
A = ++A; //NOT OK: A has been modified twice



More tips

Help your fellow programmers! Add a tip!