为什么在C程序中int 070的输出是56? [英] Why output of int 070 is 56 in C program?
本文介绍了为什么在C程序中int 070的输出是56?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include< stdio.h>
#include< conio.h>
void main()
{
int x = 070;
printf(%d,x);
getch();
}
解决方案
任何整数文字(整数常量) )以 0
开头是八进制表示。
引用 C11
,章节§6.4.4.1,整数常量
八进制常量:
0 < br>
八进制常量 八进制数
和,根据章节§7.21.6.1,%d
格式说明符与 printf()
,(强调我的)
d,i
int
参数转换为带符号十进制 [...]
因此,八进制70 ==十进制56 。
Can you explain it? Why it given 56 value as output?
#include <stdio.h>
#include <conio.h>
void main()
{
int x = 070;
printf("%d", x);
getch();
}
解决方案
Any integer literal (integer constant) starting with 0
is an octal representation.
Quoting C11
, chapter §6.4.4.1, Integer constants
octal-constant:
0
octal-constant octal-digit
and, as per chapter §7.21.6.1, for %d
format specifier with printf()
, (emphasis mine)
d,i
Theint
argument is converted to signed decimal [...]
Thereby, octal 70 == decimal 56.
这篇关于为什么在C程序中int 070的输出是56?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文