www.thecareerplus.com
The CareerPlus
Home Technical Resources Programming Expressions
Thursday 09th September 2010
 
 
What is the difference between if(0 == x) and if(x == 0)?

Discuss it!          


Nothing!. But, it's a good trick to prevent the common error of writing


if(x = 0)


The error above is the source of a lot of serious bugs and is very difficult to catch.
If you cultivate the habit of writing the constant before the ==, the compiler will
complain if you accidentally type
if(0 = x) Of course, the trick only helps when comparing to a constant.

Discuss it!          

CrackTheIntervew.NET
Advertisement
 
Top! Top!