Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C storing values that start with zero get mutated, why?

Tags:

c

int

storage

For example:

int main(){

    int x = 01234567;

    printf("\n%d\n",x);

    return 0;

}

The following code produces: 342391

If I didn't include the 0 at the beginning, the value x would be 1234567, why does C store the value this way and is there any way to get it from not doing this?

like image 349
Mark Berube Avatar asked Nov 28 '22 06:11

Mark Berube


1 Answers

Because numbers starting with 0 are represented as octal numbers. You cannot really modify this behavior, simply do not include the zero at the beginning.

like image 107
Karel Petranek Avatar answered Dec 28 '22 08:12

Karel Petranek