用C/C++打印整数

adr*_*008 3 c c++ literals octal

我有一个简单的程序.

#include <cstdio>
int main()
{
   int num = 000012345; printf("%d\n",num);
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

上面的程序给出了5349.为什么?我的意思是它应该是错的,但为什么5349?

Ash*_*hot 12

0以c/c ++ 开头的数字是八进制.

Octal  = 000012345
Decimal= 0×8?+0×8?+0×8?+0×8?+1×8?+2×8³+3×8²+4×8¹+5×8? = 5349
Binary = 1010011100101
Hex    = 14E5
Run Code Online (Sandbox Code Playgroud)