C - C++ Variables

TypeExampleUsageComment
int1[<signed | unsigned>] [<short | long | long long>] int
long int1L
long long int1LL
double1.0[long] double
float1.0F
char'1'[<signed | unsigned >]char
char*“a string”Automatically terminated with a null character.
wchar_t*L“a string”[<signed | unsigned >]wchar_t
char8_t*u8“this is a UTF-8 string with a UTF-8 character: u2018”
char16_t*u“this is a UTF-16 string with a UTF-16 character: u2018”
char32_t*U“this is a UTF-32 string with a UTF-32 character: U00002018”
booltrue, false
binary0b101C++ 2014 standard.

Declarations

Declarations use both intrinsic and user-defined types. The intrinsic types are:

[<signed | unsigned >]char
[<signed | unsigned >]wchar_t
[<signed | unsigned>] [<short | long | long long>] int
float
[long] double
bool

The keyword auto can be used if C++ can determine the type of variable itself:

auto var = 1L;               // The type of var is long int.

The keyword decltype extracts the type of an expression.

This type can then be used wherever a type name is used.

For example, the following example uses decltype to declare a second variable with same type as an existing variable:

decltype(var1) var2;         // The type of var2 is the same as var1.