Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

octal

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!

like image 517
Fitzwilliam Bennet-Darcy Avatar asked Nov 30 '22 14:11

Fitzwilliam Bennet-Darcy


1 Answers

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.

like image 50
eerorika Avatar answered Dec 05 '22 06:12

eerorika