i have a very basic question.
following is the code
the output is 10,20,30..........Code:# include<stdio.h> # include<conio.h> void main() { int i=012; int j=024; int k=036; printf("%d %d %d ",i,j,k); getch(); } >
why is it not 12,24,36?
i have a very basic question.
following is the code
the output is 10,20,30..........Code:# include<stdio.h> # include<conio.h> void main() { int i=012; int j=024; int k=036; printf("%d %d %d ",i,j,k); getch(); } >
why is it not 12,24,36?
012 is not 12 decimal its 12 octal. the 0 means treat this as octal similarly as 0x means treat this as hex. same for 024 and 036. All octal numbers(base 8)
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
You're lucky it works at all. It doesn't have to you know, because main is not a void function. That's undefined.
Quzah.
Hope is the first step on the road to disappointment.