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

Why nin

const int n = -0123;

octal literal? I thought that all octal literals should start with 0, and this does not happen, since it starts with a negative.

This is a small point that I know, but it causes me a lot of confusion!

+4
source share
3 answers

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

There are no negative whole literals, only positive ones. The literal here is 0123, which starts with 0 and therefore is octal. -there is a unary minus operator in this expression.

+9
source

. - , , . . , -1, , , (reference).

+7

, , , :

, - , . , , , 4 . , , int , (.) - .

unsigned, 4u. , 4 unsigned. , "Hello World" , , "Hello World ". , Person ++ 14 , , , Person, - . <chrono>, , s, ms ns , .

When writing an octal, -0123you say that you interpret it as an octal value in the same way 0xFFliterally interprets it as hexadecimal. A sign -is simply a way of applying the unary negation operator to a number 0123.

0
source

Source: https://habr.com/ru/post/1694977/


All Articles