首頁  >  問答  >  主體

C++中的移位问题

在以下C/C++代码中,为什么结果还是41,根本没变
unsigned int d=41;
d=(d<<32)>>32;
cout<<" 结果"<<d;
所用电脑是win10 64位系统,VS2015和DEV-C++结果都是这样。
移位操作中还有哪些是值得我们注意的?

大家讲道理大家讲道理2714 天前929

全部回覆(1)我來回復

  • 怪我咯

    怪我咯2017-04-17 15:39:48

    c++標準約定當位移右側操作數等於左側運算元的位元的個數時,運算會導致未定義行為。

    5.8.1 The operands shall be of integral or unscoped enumeration type and integral promotions are performed. The type of the result is that of the promoted left operand。 negative, or greater than or equal to the length in bits of the promoted left operand.

    回覆
    0
  • 取消回覆