2.1) Primitive Data Types of C++: Integers
Signed types:
char
(occupies 1 byte, range -128 to 127)short
(occupies 2 bytes, range -32,768 to 32,767)int
(occupies 4 bytes, range -2,147,483,648 to 2,147,483,647)long
(occupies 8 bytes, range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
Unsigned types:
unsigned char
(range 0 to 255)unsigned short
(range 0 to 65,535)unsigned int
(range 0 to 4,294,967,295)unsigned long
(range 0 to 18,446,744,073,709,551,615)
(Sizes and ranges are machine-dependent! The figures above are for a 64-bit CPU.)
Representation of literal values:
- For base 10, do not use leading zeroes - e.g. 42
- For base 8, use a leading 0 - e.g., 052
- For base 16, use a leading 0x - e.g., 0x2a, 0xff
- To indicate use of a
long
value, use L as a suffix - e.g., 42L (lowercase L is also permitted but should be avoided as it is too easily confused with the digit 1) - To indicate use of an unsigned value, use U or u as a suffix - e.g., 42U
- Use both suffixes to indicate an
unsigned long
value - e.g., 42UL