c:c_variables
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
c:c_variables [2021/02/10 16:31] – peter | c:c_variables [2021/02/10 16:37] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== C - C++ Variables ====== | ====== C - C++ Variables ====== | ||
- | ^Type^Example^Comment^ | + | ^Type^Example^Usage^Comment^ |
- | |int|1| | | + | |int|1|< |
|long int|1L| | | |long int|1L| | | ||
|long long int|1LL| | | |long long int|1LL| | | ||
- | |double|1.0| | | + | |double|1.0|< |
|float|1.0F| | | |float|1.0F| | | ||
- | |char|' | + | |char|' |
|char*|" | |char*|" | ||
- | |wchar_t*|L" | + | |wchar_t*|L" |
|char8_t*|u8" | |char8_t*|u8" | ||
|char16_t*|u" | |char16_t*|u" | ||
Line 30: | Line 30: | ||
bool | 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.1612974673.txt.gz · Last modified: 2021/02/10 16:31 by peter