C Language Comparing literal and variable


Example

Suppose you are comparing value with some variable

if ( i  == 2) //Bad-way
{
    doSomething;
}

Now suppose you have mistaken == with =. Then it will take your sweet time to figure it out.

if( 2 == i) //Good-way
{
    doSomething;
}

Then, if an equal sign is accidentally left out, the compiler will complain about an “attempted assignment to literal.” This won’t protect you when comparing two variables, but every little bit helps.

See here for more info.