Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

::::::::::::::: c program ::::::::::::::: #include void main() { int i=-0777; printf("%d",i); } explain why the output comes -551

OpenStudy (anonymous):

That is because in C the leading 0 makes C tread the number as an octal an 0777 octal does indeed equal 511 decimal.

OpenStudy (anonymous):

tread=treat and 511 should be 551

OpenStudy (anonymous):

actually I do get 511 so I am guessing the 551 was a typo

OpenStudy (anonymous):

You can test it with 0977 and you will get an error like ... error: invalid digit "9" in octal constant

OpenStudy (anonymous):

when you put "0" before any number , compiler will take it as octal number. and dec number of 777 is 551 , so you are getting 551. btw what exactly do you want to do?

OpenStudy (anonymous):

If you want to print octal value only then try following c program:- #include <stdio.h> void main() { int i=0777; printf("i=%o \n",i); }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!