【发布时间】:2019-12-03 10:07:05
【问题描述】:
为什么 printf("%llu\n", 1ull << n); 和 printf("%llu\n", 1ull << 64); 在 C++ 中的输出不同?
代码:
#include <cstdio>
int main()
{
int n = 64;
printf("%llu\n", 1ull << n);
printf("%llu\n", 1ull << 64);
return 0;
}
输出:
1
0
【问题讨论】:
-
链接的问题是关于右移,但标准不区分这两者。
-
@Yksisarvinen 感谢您的澄清。我以为我找到了左移答案。我将保持原样,因为-正如您所说-标准不区分这两者。
标签: c++ c undefined-behavior bit-shift