2.1.3. Literals
A value, such as 42
, is known as a literal because its value self-evident. Every literal has a type. The form and value of a literal determine its type.
Integer and Floating-Point Literals
We can write an integer literal using decimal, octal, or hexadecimal notation. Integer literals that begin with 0
(zero) are interpreted as octal. Those that begin with either 0x
or 0X
are interpreted as hexadecimal. For example, we can write the value 20
in any of the following three ways:
20 /* decimal */ 024 /* octal */ 0x14 /* hexadecimal */
The type of an integer literal depends on its value and notation. By default, decimal literals are signed whereas octal and hexadecimal literals can be either signed or unsigned types. A decimal literal ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.