C and C++ Data Types

Data Types — Integer Data Types

C and C++ have a number of basic data types. Each have specific uses and advantages, depending on the application.

In general, the data types can be divided into two categories; Integer types and Floating Point types.

Integer types:

Name Size (in bits, on x86) Range Notes
bool 8 (top 7 bits are ignored) 0 or 1 C++ only
char 8 -128 to 127(signed) or 0-255(unsigned) standard issue "byte"
short 16 -32768 to 32767(signed) or 0-65536(unsigned) just like a char, only twice as large
int 32 -2147483648 to 2147483647(signed) or 0-4294967296(unsigned) standard-issue integer number type
long 32 (can be 64 on other architectures) same as int ditto
long long 64 (this is a non-standard GNU extension) -9223372036854775808 to 9223372036854775807(signed) or 0-18446744073709551616(unsigned) For very huge integers

Floating Point types:

Name Size (in bits, on x86) Range Notes
float 32 +/- 1.4023x10-45 to 3.4028x10+38 general purpose real-number
double 64 +/- 4.9406x10-324 to 1.7977x10308 higher-precision real number
long double 96 (this is a non-standard GNU extention) ??? For numbers with very large ranges and high precision

Note that all Floating Point Types are always signed (they can be positive or negative), while Integer Types can be either signed or unsigned. Making an integer unsigned means that it is always non-negative and can count twice as high as a signed variable of the same type.

-- discuss ISO C99 sizes, as well as combinations (long char, long int, etc).
Styles: Default · Green · Sianse