移位操作题目

来源:互联网 发布:mysql statistics状态 编辑:程序博客网 时间:2024/06/06 18:43

int main() {


    int a =1;

    int b =32;

    printf("%d, %d\n", a<<b,1<<32);  // 结果1,1  移位操作(32|31)

    

}


对于32位的int, 多数编译器能够一次最多处理31位的左移(通过利用或运算),因此对于"<<32",32|31 = 0

使用gcc编译时会提示大于width of type


参考:http://stackoverflow.com/questions/3871650/gcc-left-shift-overflow/3871676#3871676

0 0