Is there a difference between i==0 and 0==i?

后端 未结 8 1369
我在风中等你
我在风中等你 2020-11-27 22:51

First code:

  if(i==0) {// do instructions here}

Second code:

  if(0==i) { // do instructions here }

What

8条回答
  •  渐次进展
    2020-11-27 23:33

    Functionally, they are the same in C; I'm not sure about other languages where ugly things like operator overloading come into play.

    Stylistically, the latter is extremely counter-intuitive and personally I find it extremely ugly. The point is to get the compiler to throw an error when you accidentally write = instead of ==, but good compilers have an option to warn you about this anyway so it's unnecessary.

提交回复
热议问题