Tutorial by Examples

int

Denotes a signed integer type with "the natural size suggested by the architecture of the execution environment", whose range includes at least -32767 to +32767, inclusive. int x = 2; int y = 3; int z = x + y; Can be combined with unsigned, short, long, and long long (q.v.) in order...
An integer type whose value can be either true or false. bool is_even(int x) { return x%2 == 0; } const bool b = is_even(47); // false
An integer type which is "large enough to store any member of the implementation’s basic character set". It is implementation-defined whether char is signed (and has a range of at least -127 to +127, inclusive) or unsigned (and has a range of at least 0 to 255, inclusive). const char zer...
C++11 An unsigned integer type with the same size and alignment as uint_least16_t, which is therefore large enough to hold a UTF-16 code unit. const char16_t message[] = u"你好,世界\n"; // Chinese for "hello, world\n" std::cout << sizeof(message)/sizeof(char16_t) ...
C++11 An unsigned integer type with the same size and alignment as uint_least32_t, which is therefore large enough to hold a UTF-32 code unit. const char32_t full_house[] = U"🂣🂳🂨🂸🃈"; // non-BMP characters std::cout << sizeof(full_house)/sizeof(char32_t) <<...
A floating point type. Has the narrowest range out of the three floating point types in C++. float area(float radius) { const float pi = 3.14159f; return pi*radius*radius; }
A floating point type. Its range includes that of float. When combined with long, denotes the long double floating point type, whose range includes that of double. double area(double radius) { const double pi = 3.141592653589793; return pi*radius*radius; }
Denotes a signed integer type that is at least as long as int, and whose range includes at least -2147483647 to +2147483647, inclusive (that is, -(2^31 - 1) to +(2^31 - 1)). This type can also be written as long int. const long approx_seconds_per_year = 60L*60L*24L*365L; The combination long dou...
Denotes a signed integer type that is at least as long as char, and whose range includes at least -32767 to +32767, inclusive. This type can also be written as short int. // (during the last year) short hours_worked(short days_worked) { return 8*days_worked; }
An incomplete type; it is not possible for an object to have type void, nor are there arrays of void or references to void. It is used as the return type of functions that do not return anything. Moreover, a function may redundantly be declared with a single parameter of type void; this is equivale...
An integer type large enough to represent all characters of the largest supported extended character set, also known as the wide-character set. (It is not portable to make the assumption that wchar_t uses any particular encoding, such as UTF-16.) It is normally used when you need to store character...

Page 1 of 1