0647 giving 423 in C++?

C++ exception

In C++, when an integer literal starts with as leading zero, it is interpreted as an octal(base 8) value. In the case of int a = 0657, the value 0647 is an octal value that represents the decimal value 423 (since 68^2 + 48^1 +7*8^0 = 384 + 32 +7 = 423).

So, when you print the value a using std::cout, it will display value 423.

Here is an example code snippet that demonstrates this behaviour.

e <iostream>

int main(){

int a = 0647;

std::cout << a << std::endl; // Output: 423

return 0;

}