I am wondering, what is happening when an int is starting with a zero?
int main() {
int myint = 01001;
cout << myint;
return 0;
}
Why is that outputting:
513
I have tried several compilers.
I am wondering, what is happening when an int is starting with a zero?
int main() {
int myint = 01001;
cout << myint;
return 0;
}
Why is that outputting:
513
I have tried several compilers.
Then the integer is treated as an octal number. So,
01001
equals
1 * 8 ^ 0 + 0 * 8 ^ 1 + 0 * 8 ^ 2 + 1 * 8 ^ 3 = 1 + 0 + 0 + 512 = 513
No magic in there.