What is the difference between if(CONST==variable) or if(variable==CONST)?

前端 未结 5 1102
星月不相逢
星月不相逢 2021-01-11 14:01

Is there a difference in the order of the comparison operator?

#define CONST_VALUE 5

int variable;

...

if ( variable == CONST_VALUE )   // Method 1
...

O         


        
5条回答
  •  温柔的废话
    2021-01-11 14:51

    As others mentioned, CONST_VALUE == variable avoids the = typo.

    I still do "variable == CONST_VALUE", because I think its more readable and when I see something like:

    if(false == somevariable)
    

    my bloodpressure goes up.

提交回复
热议问题