#include<stdio.h>
void main(){
int i;
i = 011;
printf("%d",i);
}
This program gives output as 9. I don't know the reason for that. Please help me to figure out why this program is giving this output.
#include<stdio.h>
void main(){
int i;
i = 011;
printf("%d",i);
}
This program gives output as 9. I don't know the reason for that. Please help me to figure out why this program is giving this output.
In C, you can represent the value 9 by:
In C/C++/Java, hex numbers begin with 0x
. Octal numbers begin with 0
.
011
is octal of 9
011 is octal number due to 0 preceding it
011 = 1*(8^1) + 1*(8^0)
= 1*8 + 1*1
= 8 +1
= 9 in decimal(%d)
0x for hex and only digits(i.e 9) for decimal