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 3112 times.
Rating of 5.3 with 4 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!