User Tools

Site Tools


c:c_variables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
c:c_variables [2021/02/10 16:30] peterc: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|<nowiki>[<signed | unsigned>] [<short | long | long long>] int</nowiki>| |
 |long int|1L| | |long int|1L| |
 |long long int|1LL| | |long long int|1LL| |
-|double|1.0| |+|double|1.0|<nowiki>[long] double</nowiki>| |
 |float|1.0F| | |float|1.0F| |
-|char|'1'| |+|char|'1'|<nowiki>[<signed | unsigned >]char</nowiki>| |
 |char*|"a string"|Automatically terminated with a null character.| |char*|"a string"|Automatically terminated with a null character.|
-|wchar_t*|L"a string"| |+|wchar_t*|L"a string"|<nowiki>[<signed | unsigned >]wchar_t</nowiki>| |
 |char8_t*|u8"this is a UTF-8 string with a UTF-8 character: u2018"| | |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"| | |char16_t*|u"this is a UTF-16 string with a UTF-16 character: u2018"| |
Line 22: Line 22:
 Declarations use both intrinsic and user-defined types. The intrinsic types are: Declarations use both intrinsic and user-defined types. The intrinsic types are:
  
 +<code c++>
 [<signed | unsigned >]char [<signed | unsigned >]char
 [<signed | unsigned >]wchar_t [<signed | unsigned >]wchar_t
Line 28: Line 29:
 [long] double [long] double
 bool bool
 +</code>
 +
 +----
 +
 +The keyword **auto** can be used if C++ can determine the type of variable itself:
 +
 +<code>
 +auto var = 1L;               // The type of var is long int.
 +</code>
 +
 +----
 +
 +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:
 +
 +<code>
 +decltype(var1) var2;         // The type of var2 is the same as var1.
 +</code>
 +
c/c_variables.1612974647.txt.gz · Last modified: 2021/02/10 16:30 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki