+3

Why numbers starting from 0 is treated as octal in cpp?

For ex: int a=010; cout<<a; Outputs 8

2/21/2020 10:13:10 AM

Nandan Kumar

2 Answers

New Answer

+9

Such prefix are used for integer literals, to signal the intended base for the integer literal. There are some well known integer literal prefix commonly used. Among which are: 0b - Prefix for binary integer literal 0 - Prefix for octal integer literal 0x - Prefix for hexadecimal integer literal Learn more about integer literals, prefix and suffix here 👇 https://www.tutorialspoint.com/cprogramming/c_constants.htm

+7

It is the convention used in all languages.