sizeof — size of a type or object in bytes
The sizeof operator returns a type's size in bytes as a constant of type std::size_t. Its expression operand is not evaluated, and an array retains its full size rather than being converted to a pointer.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
The sizeof operator returns a type's size in bytes as a constant of type std::size_t. Its expression operand is not evaluated, and an array retains its full size rather than being converted to a pointer.
The sizeof... operator computes the number of elements in a parameter pack, not their size in bytes. Its result is an integral constant of type std::size_t; an empty pack yields 0.
The <=> operator, called spaceship, describes an ordering relationship between values. Standard result categories distinguish less, equivalent, greater, and sometimes unordered. In a class, a defaulted definition provides lexicographical comparison of subobjects.
static_cast<T>(expression) explicitly converts an expression to T under the language's conversion rules. The compiler checks whether the conversion is permitted, but does not guarantee value preservation or the validity of a class-hierarchy downcast.
The << operator writes values to an output stream. Learn the distinction between member overloads and non-member functions, and how to support a custom type while preserving chained insertion.
The symbol `-` means subtraction in `a - b` and arithmetic negation in `-x`. It can also move a pointer or calculate the distance between pointers. Correct results depend on type conversions, numeric ranges, and array boundaries.
The -= operator subtracts the right operand from the left operand's value and stores the result in the left object. For the built-in operator, the left operand is evaluated only once; type conversions and pointer arithmetic restrictions still apply.
The typeid operator exposes type information. For a polymorphic glvalue it identifies the dynamic type; otherwise it uses the static type.
Unary minus, written as -expression, computes the negated value. Learn how integral promotions affect the result, how unsigned negation works, and when signed overflow is a risk.
Unary + preserves its operand's value but can change its type through integral promotion. For an eligible noncapturing lambda, it can also force conversion to a function pointer.
The #include directive makes a header or source file's contents available during preprocessing. The <header> and "file" forms use different searches; the implementation defines the specific search rules.
Aggregate initialization initializes the elements of an aggregate, usually with a brace-enclosed list. Learn element ordering, omitted-member values, and the restrictions on designated initializers in C++23.
The declaration using AliasName = Type; gives a type another name without creating a distinct type. Learn its equivalence to typedef and how const applies to pointer aliases.
T name[N] declares a built-in array of N elements of type T. Its bound must be a positive compile-time constant; the elements occupy contiguous storage.
CTAD lets you omit class template arguments when initializing an object. The compiler selects a specialization using candidates derived from constructors and deduction guides. A guide selects the type but does not replace a constructor.
A const qualifier after a member function's parameter list restricts modification of the object through this. It permits calls through const objects, references, and pointers, but does not imply complete freedom from side effects.
`= default` requests a compiler-generated implementation of a comparison operator. Defaulted `operator==` and `operator<=>` compare class subobjects in a defined order: the former tests equality, and the latter determines ordering. Defaulted secondary operators such as `!=` and `<` use rewritten comparisons instead of comparing subobjects themselves.
A function definition using = delete prohibits its use. The function still participates in overload resolution, allowing it to block unwanted calls.
A floating-point literal writes a numeric value directly in source code. The suffix f or F gives it type float; without a suffix it has type double, and with l or L it has type long double.
A fold expression combines pack elements using a binary operator. Learn the four syntax forms, how fold direction controls grouping, and the empty-pack rules through a small summation example with an initial value.
An integer literal writes a value directly in code. Its base, value, and optional suffix determine its type; for `ULL`, `unsigned long long` is the only standard candidate.
A lambda expression creates a callable object. Learn capture by copy and reference, init-capture, the meaning of mutable, and generic lambdas with auto parameters.
A namespace alias gives an existing namespace an additional, usually shorter name. It does not copy the namespace's members: both names refer to the same namespace.
A non-type template parameter (NTTP) represents a value rather than a type. It lets you establish properties such as a buffer's size at compile time instead of passing them as function arguments.