print(0,0) for print(int,double)/print(double,int)).
double + int in double precision).
=; rejected by {} initialization.
\n is the newline character. The
characters are immutable — pass as const char*.
char*.
std:: qualifies a name as belonging to the
standard-library namespace.
* =
contents of.
0/NULL.
*), cannot be rebound after
initialization, and there is no null reference.
const T& — read access without copying, no modification (e.g.
sum(const vector<double>&)).
constexpr function is pure (no side effects) and may still be called with
runtime arguments (result then isn't constant).
constexpr declarations.
' in a numeric literal for readability (e.g.
3.14159'26535).
for (auto x : seq) iterates copies;
for (auto& x : seq) iterates references (can mutate).
| Type | Meaning | Example | Note |
|---|---|---|---|
bool |
Boolean | true, false |
— |
char |
Character | 'a', '9' |
Natural size = 1 byte; sizeof(char)==1 |
int |
Integer | 42, -273 |
Often 4 bytes |
double |
Double-precision float | 3.14, 6.626e-34 |
— |
unsigned |
Non-negative integer | 0, 999 |
Use for bit manipulation only |
Sizes are implementation-defined and vary between machines; use sizeof to query
and aliases like int32_t for guaranteed widths.
| Form | Base | Example |
|---|---|---|
0b... |
Binary | 0b10101010 |
0x... |
Hexadecimal | 0xBAD12CE3, 0x3.243F'6A88'85A3'08D3 |
0... |
Octal | 0334 |
| no prefix | Decimal | 42 |
| decimal point / exponent | Floating-point | 3.14, 314e-2 |
Single quotes are digit separators: 3.14159'26535'89793.
x + y, +x, x - y, -x, x * y,
x / y, x % y (remainder, integers)
x == y, x != y, x < y, x > y,
x <= y, x >= y
| Operator | Kind | Result |
|---|---|---|
& | ^ ~ |
Bitwise and/or/xor/complement | Value of operand type, per bit |
&& || ! |
Logical and/or/not | true/false only |
x += y, x -= y, x *= y, x /= y,
x %= y, ++x, --x
x.y, x->y, x(y),
x[y], x<<y, x>>y,
x&&y, x||y
x += y)f(x)+g(y), function arguments)
| Declaration | Type | Meaning |
|---|---|---|
T a[n] |
T[n] |
array of n Ts |
T* p |
T* |
pointer to T |
T& r |
T& |
reference to T |
T f(A) |
T(A) |
function taking A, returning T |
| Scope | Extent | Destroyed |
|---|---|---|
| Local (function/lambda) | Declaration → end of { } block |
At block end |
| Class (member) | Opening { → matching } |
With the owning object |
| Namespace | Declaration → end of namespace | End of program |
| Global | Whole program | End of program |
Objects created with new live until delete; unnamed objects are
temporaries or new results.
| Form | Example | Notes |
|---|---|---|
= |
int i1 = 7.8; |
Traditional (C); allows implicit narrowing (i1 becomes 7) |
{ } |
int i2 {7.8}; |
General form; rejects narrowing (error) |
= { } |
double d3 = {2.3}; |
Same as { }; = optional |
auto |
auto d = 1.2; |
Type deduced from initializer |
Rule: if in doubt, use { }. Don't declare a name until you have
a value.
| Keyword | Evaluated | Callable with runtime args? | Use for |
|---|---|---|---|
const |
Run time | — | Interface promises ("won't modify"), runtime constants |
constexpr |
Compile time (may fall back to runtime) | Yes | Named constants, pure functions usable in constant expressions |
consteval |
Compile time only | No | Functions that must run at compile time |
| Pointer | Reference | |
|---|---|---|
| Access | Need *p |
Implicit |
| Rebinding | Can point elsewhere (p = q) |
Cannot rebind after init |
| Null | nullptr allowed |
No null reference |
| Representation | Both are machine addresses | |
| Assignment | Reassigns the pointer variable | Writes through to the referred object |
Assignment copies a value into an existing object (x = y → x == y;
objects stay independent, for all types like C). Initialization turns raw,
uninitialized memory into a valid object; using an uninitialized variable is undefined.
Argument passing and return values use initialization semantics — that is how
pass-by-reference works.