1

なぜそれが起こるのかわかりませんでした!理由を知りたい。

{
int i=01;
printf("%d\n",i);
}
output: 1

しかし

{
int i=011;
printf("%d\n",i);
}
output: 9

誰も答えを持っていますか?

4

3 に答える 3

11

0118 進定数です。11 (b8) = 9 (b10).

C11 (n1570)、§ 6.4.4.1 整数定数
8 進定数は、接頭辞 0 と、それに続くオプションの数字 0 ~ 7 のシーケンスのみで構成されます。

于 2012-11-10T10:33:57.153 に答える
4

011 = 8 進数、(1*8)+1=9 .........................

于 2012-11-10T10:34:55.293 に答える
-1
The numbers which are preceded by 0 is called octal numbers in c programming .
to evaluate such an expression we simply follow a conversion rule of converting octal to decimal number system
For conversion the following steps are  to be proceed
such as 011
here 0 indicate the number is octal 
and we are require to convert 11 which is (base 8) to decimal (base 10)

11= 1x8^1+1x8^0
   =8+1
   =9
于 2015-03-29T16:01:31.230 に答える