检查长使用类型的限制
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)
考虑到.之后立即否定它不会使操作-员的操作数本身为负.