当显示变量 "int a = 011" 的值时,我得到 9。为什么?

When displaying the value of variable "int a = 011", I get 9. Why?

使用此代码段:

int a = 011;
printf("a = %d", a);

为什么结果是

a = 9

前导 0,在 int 文字或 int 常量中,表示 octal 值。它被称为八进制常数。

相关:C11 标准,第 6.4.4.1 章,整数常量,第 3 段,

An octal constant consists of the prefix 0 optionally followed by a sequence of the digits 0 through 7 only.

011 是一个八进制值,它的十进制等值是 9。前面带有 0 的整数文字表示八进制值。
printf 中使用 %o 说明符以八进制打印值。

在数字文字的开头使用 0,指定八进制系统。而11在八进制中就是1*8 + 1 = 9.