C语言中的八进制文字

当我们通过将“0”放在数字之前来初始化一个值时,该数字被视为八进制。例如,“10”读作10,但“010”读作8。

null

例如:

Input : 0101
Output : 65

Input : 01010
Output : 520

#include<iostream>
using namespace std;
int main()
{
int x = 0101;
cout << x;
return 0;
}


输出:

65

#include<iostream>
using namespace std;
int main()
{
int x = 020;
cout << x;
return 0;
}


输出:

16

#include<iostream>
using namespace std;
int main()
{
int x = 090;
cout << x;
return 0;
}


输出:

Compiler Error : 9 is not a valid digit in octal number.
© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享