Sunday, July 12, 2009

Can anyone please help me with this C program??

#include%26lt;stdio.h%26gt;


void main()


{


int a=012;


int b=034;


int c=056;


printf("a= %d\n",a);


printf("b=%d\n",b);


printf("c=%d\n",c);


}


if u tell me the answers r


a=12


b=34


c=56


then yr answer is wrong...when u run this program the answer is


a=10


b=28


c=46


can anyone tell me how we got these values.please its urgent

Can anyone please help me with this C program??
this sounds confusing???
Reply:This is happening because in the C language a number with a leading zero is interpreted as octal.





So 012 (octal) = 8 + 2 = 10 (decimal), 034 (octal) = 3*8+4 = 28 (decimal) and 056 (octal) = 5*8+6 = 46 (decimal).


No comments:

Post a Comment