Search code examples
c++octal

How is it possible that an octal literal can be negative?


Why is n in

const int n = -0123;

an octal literal? I thought that all octal literals had to start with a 0, and this one doesn't since it starts with a negative.

It's a small point I know but It's causing me great confusion!


Solution

  • How is it possible that an octal literal can be negative?

    There are no negative integer literals, only positive. The literal here is 0123 which does start with a 0 and is thus octal. - in that expression is the unary minus operator.