C++ Basics — Quick Reference & Glossary

A Tour of C++, Chapter 1 — the canonical vocabulary and cheat sheet for this course.


Glossary

Glossary
Type
A set of possible values and a set of operations (for an object). Determines operations and memory layout.
Object
Some memory that holds a value of some type. Constructed before use, destroyed at end of scope.
Value
A set of bits interpreted according to a type.
Variable
A named object.
Declaration
A statement that introduces an entity and specifies its type. A function cannot be called unless declared.
Definition
A declaration that also gives the entity its body/storage.
Function overloading
Multiple functions with the same name but different argument types; the compiler picks the best match. All overloads should share the same semantics.
Ambiguous call
Two matching overloads where neither is better — a compile-time error (e.g. print(0,0) for print(int,double)/print(double,int)).
Usual arithmetic conversions
Implicit conversions so mixed-type expressions compute at the highest precision of their operands (e.g. double + int in double precision).
Narrowing conversion
A conversion that loses information (double→int, int→char). Allowed implicitly with =; rejected by {} initialization.
String literal
A sequence of characters in double quotes; \n is the newline character. The characters are immutable — pass as const char*.
C-style string
A zero-terminated array of char pointed to by a char*.
Namespace
A named scope for declarations; std:: qualifies a name as belonging to the standard-library namespace.
Array
A contiguous sequence of elements of the same type; lower bound is 0; size must be a constant expression.
Pointer
A variable holding the address of an object (a machine address). Prefix * = contents of.
nullptr
The null pointer; one shared value for all pointer types. Use instead of 0/NULL.
Reference
An alias to an object; implicit dereference (no *), cannot be rebound after initialization, and there is no null reference.
Const reference
A const T& — read access without copying, no modification (e.g. sum(const vector<double>&)).
const
"I promise not to change this value." Compiler-enforced; may be computed at run time.
constexpr
"Evaluated at compile time." The value must be computed by the compiler. A constexpr function is pure (no side effects) and may still be called with runtime arguments (result then isn't constant).
consteval
"Must be evaluated at compile time." Cannot be called with non-constant arguments.
Constant expression
An expression the compiler can evaluate. Required for array bounds, case labels, template value arguments, constexpr declarations.
Scope
The region where a name is visible: local (function/lambda block), class (member), namespace, or global.
Initialization
Making an uninitialized piece of memory into a valid object. The semantics of argument passing and function return.
Assignment
Copying a value into an existing object; a machine copy for built-in types. Never rebinds a reference.
auto
Type deduced from the initializer; use when the type is obvious or redundant.
Digit separator
A single quote ' in a numeric literal for readability (e.g. 3.14159'26535).
Range-for
for (auto x : seq) iterates copies; for (auto& x : seq) iterates references (can mutate).

Fundamental Types

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.

Literals

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.

Operators

Arithmetic

x + y, +x, x - y, -x, x * y, x / y, x % y (remainder, integers)

Comparison

x == y, x != y, x < y, x > y, x <= y, x >= y

Logical

Operator Kind Result
& | ^ ~ Bitwise and/or/xor/complement Value of operand type, per bit
&& || ! Logical and/or/not true/false only

Modifying a variable

x += y, x -= y, x *= y, x /= y, x %= y, ++x, --x

Evaluation order

Declarator Operators

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

Scopes & Lifetime

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.

Initialization Forms

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.

const vs constexpr vs consteval

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 vs Reference

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 vs Initialization

Assignment copies a value into an existing object (x = yx == 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.


← Back to Lesson 1