C++中的移位问题
大家讲道理
大家讲道理 2017-04-17 15:37:48
0
1
926

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

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
刘奇

The C++ standard stipulates that when the right operand of the displacement is equal to the number of bits of the left operand, the operation will lead to undefined behavior.

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. The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!