Tuesday, April 25, 2006

Reversing equality test to avoid errors

Common mistake
if(x=2)
instead of
if(x==2)
Write the rvalue of the expression at the left side of the equality operator (==):
if(2==x)
In this case the compiler will warn you if you typed the assignment operator (=) by mistake.

5 comments:

Sumant said...

Many people find this (2==x) less clear to read than (x==2) !

Sumant said...

Many people find this (2==x) less clear to read than (x==2) !

Kunal Chopra said...

hey jacob,

would love to learn about ur experience. lemme know.

Thanks,

Kunal

Kunal Chopra said...

sure - here you go - kunal.b.chopra@gmail.com

take care,

Kunal

Anonymous said...

hey jacob...could you please email me ur interview experience with microsoft...i hv an interview on monday...n wud reallly appreciate ur inputs..thnax