c:c_variables
This is an old revision of the document!
C - C++ Variables
Type | Example | Usage | Comment | |
---|---|---|---|---|
int | 1 | |||
long int | 1L | |||
long long int | 1LL | |||
double | 1.0 | |||
float | 1.0F | |||
char | '1' | [<signed | unsigned >]char | |
char* | “a string” | Automatically terminated with a null character. | ||
wchar_t* | L“a string” | |||
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” | |||
bool | true, false | |||
binary | 0b101 | C++ 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.
c/c_variables.1612974922.txt.gz · Last modified: 2021/02/10 16:35 by peter