|
|
5 in this piece of code was a literal constant. |
|
1776 always represents the value one thousand seven hundred seventy-six.0 (zero) character. And for hexadecimal, they are preceded by the characters 0x (zero, x). For example, the following literal constants are all equivalent to each other: |
|
int. However, certain suffixes may be appended to an integer literal to specify a different integer type:| Suffix | Type modifier |
|---|---|
u or U | unsigned |
l or L | long |
ll or LL | long long |
unsigned long or unsigned long long. |
|
e character (that expresses "by ten at the Xth height", where X is an integer value that follows the e character), or both a decimal point and an e character: |
|
double. Floating-point literals of type float or long double can be specified by adding one of the following suffixes:| Suffix | Type |
|---|---|
f or F | float |
l or L | long double |
|
|
e, f, l) can be written using either lower or uppercase letters with no difference in meaning. |
|
'), and to express a string (which generally consists of more than one character), we enclose the characters between double quotes (").
x
'x'
x alone would refer to an identifier, such as the name of a variable or a compound type, whereas 'x' (enclosed within single quotation marks) would refer to the character literal 'x' (the character that represents a lowercase x letter).\n) or tab (\t). These special characters are all of them preceded by a backslash character (\).| Escape code | Description |
|---|---|
\n | newline |
\r | carriage return |
\t | tab |
\v | vertical tab |
\b | backspace |
\f | form feed (page feed) |
\a | alert (beep) |
\' | single quote (') |
\" | double quote (") |
\? | question mark (?) |
\\ | backslash (\) |
'\n'
'\t'
"Left \t Right"
"one\ntwo\nthree"
\) followed by the code expressed as an octal (base-8) or hexadecimal (base-16) number. For an octal value, the backslash is followed directly by the digits; while for hexadecimal, an x character is inserted between the backslash and the hexadecimal digits themselves (for example: \x20 or \x4A). |
|
|
|
\) at the end of line is considered a line-continuation character that merges both that line and the next into a single line. Therefore the following code: |
|
|
|
char. A different character type can be specified by using one of the following prefixes:| Prefix | Character type |
|---|---|
u | char16_t |
U | char32_t |
L | wchar_t |
char16_t and uppercase for char32_t and wchar_t.u, U, and L, two additional prefixes exist:| Prefix | Description |
|---|---|
u8 | The string literal is encoded in the executable using UTF-8 |
R | The string literal is a raw string |
R"sequence( and a final )sequence", where sequence is any sequence of characters (including an empty sequence). The content of the string is what lies inside the parenthesis, ignoring the delimiting sequence itself. For example: |
|
"string with \\backslash". The R prefix can be combined with any other prefixes, such as u, L or u8.true, false and nullptr:true and false are the two possible values for variables of type bool.nullptr is the null pointer value. |
|
|
|
|
|
31.4159 |
#define identifier replacement identifier in the code is interpreted as replacement, where replacement is any sequence of characters (until the end of the line). This replacement is performed by the preprocessor, and happens before the program is compiled, thus causing a sort of blind replacement: the validity of the types or syntax involved is not checked in any way. |
|
31.4159 |
#define lines are preprocessor directives, and as such are single-line instructions that -unlike C++ statements- do not require semicolons (;) at the end; the directive extends automatically until the end of the line. If a semicolon is included in the line, it is part of the replacement sequence and is also included in all replaced occurrences.Variables and types | Index | Operators |