Feb 062013
 

While comparing a variable with a constant (literal) in C/C++ language, which of the two ways of comparison should we use ?

    if( x == 2 ) ...

    if( ptr == NULL ) ...

Or

    if( 2 == x ) ...

    if( NULL == ptr ) ...

In the first comparison we are writing variable on the Left side of == and literal (constant) on right side. whereas, in the second form we are writing the literal (2, NULL, etc.) on the left side of ==.
Continue reading »