assignment operators

is the following code correct?:

if(0!= variablename)
{ ... }
Well that depends on what the type and value of variablename is, and what you're trying to check regarding it.
its a normal integer.. wat am i trying to achieve with this type of code??
wat am i trying to achieve with this type of code??


Do you want to execute the code inside the braces if variablename is zero, or if variablename is not zero?

I note that you called this thread "assignment operators" but there are no assignment operators in the code you presented.
Last edited on
see whatever i'm trying to achieve .. some form of execution.. i could've done with
" if(variablename!=0) " .. correct? instead i saw this convention somewhere and i want to know why its used..
It is valid syntax. The choice is yours - either will work. Some people get into the habit of putting the value first so that they cannot make the common mistake of writing:
if ( variable = 0)
when they meant to write
if (variable == 0)
Both will compile and work, but they are very different.

Turning round the order means that writing

if ( 0 = variable)
by mistake will cause a compile-time error, and only
if ( 0 == variable) will work.
Last edited on
OK Thanks a lot.. So basically they are the same right? " if(0==var) " is essentially checking if var is zero.. right?
Topic archived. No new replies allowed.