Why do some people write if(0 == x) instead of if(x == 0)?
It's a trick to guard against the common error of writing
if(x = 0)If you're in the habit of writing the constant before the ==, the compiler will complain if you accidentally type
if(0 = x)Evidently it can be easier to remember to reverse the test than it is to remember to type the doubled = sign.
References:
H&S Sec. 7.6.5 pp. 209-10
Read sequentially: prev next up top
This page by Steve Summit // Copyright 1995 // mail feedback