Why does this happen? Strange leading zero compiler action.

I can't find the reason for this.

int NumberToBeWritten1 = 0123;
int NumberToBeWritten2 = 123;
void setup() {
Serial.begin(115200);
}

void loop() {
Serial.print(" Value1: ");
Serial.print(NumberToBeWritten1);
Serial.print(" Value2: ");
Serial.print(NumberToBeWritten2);
delay(500000);
}

And here is the output:

Value1: 83 Value2: 123

The compiler interprets a leading zero to mean that the following number is OCTAL (i.e. base 8 ). 123 is the octal equivalent of 83

...R

Thanks. Who uses Octal anymore? I thought they left that in the seventies.

sevenoutpinball:
Thanks. Who uses Octal anymore? I thought they left that in the seventies.

Octal is a number base like any other. It can't be 'left' in the seventies or anywhere / anywhen else. It will exist for all time, with or without this Universe or any other Universe or no Universe, whatever you think of it.

You funny guy.

Just as seven[outpinb]al base…

sevenoutpinball:
Thanks. Who uses Octal anymore? I thought they left that in the seventies.

Hey! I resemble that remark.

SteveMann:
Hey! I resemble that remark.

Relax, I’m old too. What planes do you fly?

Octal is still useful on *nix systems to manipulate file permissions since they're grouped in sets of 3 (read/write/execute):

# chmod -R 0777 /

Fun times.