在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/C  網(wǎng)絡(luò)安全/ a>=b 是 先判斷a是否等于b 還是先判斷a是否大于b?

a>=b 是 先判斷a是否等于b 還是先判斷a是否大于b?

換句話說,
a>=b
等同于
a==b||a>b
還是
a>b||a==b?

回答
編輯回答
夏夕

Update:

如果等于這個,程序會更慢,我覺得應(yīng)該等同于a == b || a > b才對。

That's not true. Your platform will not split >= into == and >. The implementation varies from platform to platform and compiler to compiler. From Assembly(https://godbolt.org/g/6MCvQq):

if (a >= b)

=>

  mov eax, dword ptr [rbp - 12]
  cmp eax, dword ptr [rbp - 16]
  jl .LBB0_4

   if (a > b)

=>

   cmp r8d, dword ptr [rbp - 16]
   mov dword ptr [rbp - 20], eax # 4-byte Spill
   jle .LBB0_2

Both have 3 instructions.

Also take a look at these awesome answers: https://stackoverflow.com/que...


Both are true. || is logic or operator in some languages(which belongs to logic operators). I assume you have limited the symbols to c++(because you didn't use the more general terms like logic or and logic and. In standard ml, logic or is expressed as or, same for logic and)

In c++, please correct = to ==. The former is a Direct assignment operator, while the latter is Equal to operator. If a satisfy the condition, the b will not be used. For example:

if (a && b)

is equal to

if (a)
    if(b)
        ...
        

BTW, in some algorithms, if you want to judge if a node exists (like arr[x][y] == 'x'), it should be put in b rather than a. Because sometimes a is used to filter out-of-range conditions.

2017年5月21日 10:09
編輯回答
厭遇

a > b || a == b等價于a == b || a > b,||有一個真就為真。

2018年5月2日 01:29
編輯回答
有你在

a > b || a == b, a == b||a > b ,這兩種都一樣

2017年7月13日 01:38
編輯回答
陌顏

為啥我覺得這兩個沒區(qū)別啊

2017年5月12日 10:48
編輯回答
若相惜

都對,|| 有一個為真就是真,

2017年11月3日 23:33
編輯回答
維她命
a > b || a == b
2018年3月2日 07:18