Hi I am having problem in understanding of displaying octal numbers.Following is my code.
int main(int argc,char *argv)
printf("This number %o is octal of 12.\n",octal);
printf("This number %d is non octal.\n",nonoctal);
Output displayed is
This number 14 is octal of 12
This number 10 is non octal
Here the first statement in output is fine.But why is the second statement gives output 10 instead of 012.
var octal ( 12 ) in decimal, convert to octal = 14
var nonoctal (012) in octal, convert to decimal = 10
Here the compiler interprets the leading zero to mean that this number is in octal notation, so it becomes in decimal 1*8 + 2 = 10
If you want to display leading zeros, you need to specify that when using printf:
printf("This number %03d is padded with leading zeros.\n", 10);
thanks cronopio and Chervil.your replies are really helpful.:)