Integer Constants in C++
C++ understands any symbol that begins with a digit and contains only digits to be an integer constant. The following are all legal constants in C++:
123 1 256
A constant cannot contain any funny characters. The following is not legal:
The following is legal but doesn’t mean what you may think:
This actually defines the sum of two constants 123 and 456, or the value 579.
Normally C++ assumes that constants are decimal (base 10). However, for historical reasons, a number that begins with a 0 is assumed to be octal (base 8). By the same token, a number that starts with 0x or 0X is assumed to be hexadecimal, using the letters A through F or a through f for the digits beyond 9. Thus 0xFF, 0377, and 255 are all equivalent.
Don’t start a constant with 0 unless you mean it to be in octal.
An integer constant can have certain symbols appended to the end to change its type.