Literals are constant values that are directly inserted into the source code. They represent specific data values and are used to initialize variables or express values within expressions.
10
, -25
).012
, 037
).0x1A
, 0xFF
).0b1010
, 0b1111
).u
or U
: unsigned integerl
or L
: long integerul
or UL
: unsigned long integer3.14
, -2.5
).3.14e2
, -2.5E-3
).f
or F
: floatl
or L
: long double'a'
, 'z'
).\n
: newline\t
: tab\r
: carriage return\b
: backspace\f
: form feed\\
: backslash\?
: question mark\'
: single quote\"
: double quote"Hello, world!"
).L
(e.g., L"Wide string"
).true
and false
represent Boolean values.nullptr
represents a null pointer.
int decimal_int = 10;
int octal_int = 012;
int hex_int = 0xA;
int binary_int = 0b1010;
float float_num = 3.14f;
double double_num = 2.71828;
char character = 'A';
char newline_char = '\n';
std::string str = "Hello, world!";
std::wstring wstr = L"Wide string";
bool is_true = true;
bool is_false = false;
int* ptr = nullptr;