When an integer is initialized as int a = 010, a is actually set to 8, but for int a = 10, a is set to 10.
Can anyone tell me why a is not set to 10 for int a = 010?
When an integer is initialized as int a = 010 , a is actually
Share
Because it’s interpreting
010as a number in octal format. And in a base-8 system, the number10is equal to the number8in base-10 (our standard counting system).More generally, in the world of C++, prefixing an integer literal with
0specifies an octal literal, so the compiler is behaving exactly as expected.