Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道,当 int 以零开头时会发生什么?
int main() { int myint = 01001; cout << myint; return 0; }
为什么输出:
513
我尝试了几种编译器。
然后整数被视为八进制数。所以,
01001
等于
1 * 8 ^ 0 + 0 * 8 ^ 1 + 0 * 8 ^ 2 + 1 * 8 ^ 3 = 1 + 0 + 0 + 512 = 513
里面没有魔法。