::::::::::::::: c program :::::::::::::::
#include
void main()
{
int i=-0777;
printf("%d",i);
}
explain why the output comes -551
Still Need Help?
Join the QuestionCove community and study together with friends!
Sign Up
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?
Still Need Help?
Join the QuestionCove community and study together with friends!
Sign Up
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);
}