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

后端 未结 8 1371
我在风中等你
我在风中等你 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:41

    In C# there is no difference. However in C++ there was a difference in performance which is why you see both used in C# code these days - actually I'm thinking of i++ vs ++i about performance - 0 == i is a common coding recommendation in C/C++ to avoid i = 0 as an accidental operation

    0 讨论(0)
  • 2020-11-27 23:42

    When you write (0==i) the error of using single equal to sign by mistake (e.g. ) if ( i = 0) is eliminated. Nothing else.

    0 讨论(0)
提交回复
热议问题