nilcit nilcit - 1 month ago 12
C++ Question

Why is C++ behaving weirdly when I add leading 0's to an int?

Why is

cout << 0110 << endl;


printing out 72?

I didnt' think adding leading 0's to an int would make any difference, shouldn't '0110' be the same as '110'?

Answer Source

Note that 0110 is an octal-literal:

octal-literal is the digit zero (0) followed by zero or more octal digits (0, 1, 2, 3, 4, 5, 6, 7)

That's why you're getting 72 when printing out it, it's not same as 110.