小编Gur*_*hav的帖子

左移或右移带有负数的整数,这是定义的行为吗?

我尝试了下面的代码,在这两种情况下,即(左移和右移)我得到的输出为 0

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a=20;

    a=a<<-1;
    cout<<a;
    int x=20;
    x=x>>-1;
    cout<<x;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ bit-shift

0
推荐指数
1
解决办法
86
查看次数

标签 统计

bit-shift ×1

c++ ×1