相关疑难解决方法(0)

为什么左移32次无符号数不会产生零?

#include <iostream>

using namespace std;

int main()
{
   cout << "sizeof(unsigned int): " << sizeof(unsigned int) << endl; 
   unsigned a = 1;
   int i = 0;
   while (a) {         
        cout << "a[" << i++ << "]: " << a << endl;        
        a <<= 1;
   }

   cout << "a[" << i << "]: " << a << endl;

   unsigned b = 1;
   unsigned c = (b << 31);
   unsigned d = (b << 32);

   cout << "c: " << c << …
Run Code Online (Sandbox Code Playgroud)

c++ undefined-behavior

5
推荐指数
2
解决办法
797
查看次数

标签 统计

c++ ×1

undefined-behavior ×1