(签名)多头的实际下限是多少?

Gio*_*o A 6 c++ g++

检查长使用类型的限制

std::cout << std::numeric_limits<long long>::min();
Run Code Online (Sandbox Code Playgroud)

我得到-9223372036854775808

但是在编译以下代码时:

int main() {
   long long l;
   l=-9223372036854775808LL;
}
Run Code Online (Sandbox Code Playgroud)

我收到警告:

test.cpp:3:7: warning: integer constant is so large that it is unsigned.
test.cpp:3: warning: this decimal constant is unsigned only in ISO C90
Run Code Online (Sandbox Code Playgroud)

我错过了什么?非常感谢您的帮助.

乔治

Joh*_*itb 13

9223372036854775808LL是一个正数.所以你需要采取

std::cout << std::numeric_limits<long long>::max();
Run Code Online (Sandbox Code Playgroud)

考虑到.之后立即否定它不会使操作-员的操作数本身为负.

  • 至于为什么你的系统中min和max值在零附近并不完全对称,你可能想要阅读[Two's complement](http://en.wikipedia.org/wiki/Two's_complement). (4认同)