+ 3

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

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

21st Feb 2020, 10:13 AM
Nandan
Nandan - avatar
2 Answers
+ 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
21st Feb 2020, 10:52 AM
Ipang