Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

Knowledge base — C++

Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.

Entries: 674

C++

delete and delete[] — destroying dynamic objects

A delete expression destroys a single object created by new, while delete[] destroys an array created by new[]. Choosing the matching form is mandatory; mixing the forms causes undefined behavior.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Dereference operator *

The unary * operator denotes the object or function addressed by a pointer. It enables reading and, when the type permits, modifying the pointed-to object; it does not create a copy.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Division operator /

The / operator calculates a quotient. For integer operands it discards the fractional part toward zero; a floating-point operand can change the calculation type. Convert before dividing to preserve a fractional result.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Division assignment operator /=

The /= operator divides the left operand's value by the right operand and stores the result back. Operand types determine the kind of division, and storing the result may require another conversion. The left operand is evaluated only once.

Basic · C++23; repository compiler flag, production runtime not attested
C++

dynamic_cast — checked casting in class hierarchies

dynamic_cast converts pointers and references within class hierarchies, checking conversions at runtime where required. A failed pointer cast returns nullptr, whereas a failed reference cast throws std::bad_cast.

Intermediate · C++23; repository compiler flag, production runtime not attested
C++

Equality operator ==

The == operator tests operands for equality. Built-in comparison returns bool, while classes can define comparison through operator==. Do not confuse == with assignment = or pointer comparison with comparison of the pointed-to values.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Function call operator ()

Parentheses () following an expression form a call with the supplied arguments. This syntax calls functions and callable objects; a class can provide it through an operator() member function.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Operator >= — greater than or equal to

The >= operator checks whether the left operand is greater than or equal to the right operand. Built-in comparisons return bool. Numeric comparisons require attention to type conversions, particularly when mixing signed and unsigned integers.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Greater-than operator (>)

The > operator tests whether the left operand is greater than the right. A built-in comparison returns bool; equal values produce false. Learn about numeric conversions, chained-comparison pitfalls, and the distinction between built-in and overloaded comparisons.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Increment operator ++

The ++ operator increments its operand. For built-in types, ++x provides the modified object, whereas x++ produces a copy of the previous value. Learn the operand requirements, the distinction between the two forms, and their basic restrictions.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Inequality operator (!=)

The != operator tests whether its operands are unequal. The built-in operation returns bool after required conversions. Classes can define operator!= or use an eligible operator== through comparison rewriting rules.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Bitwise left-shift operator <<

The built-in << operator shifts an integer value's bits left, filling vacated positions with zeros. The shift count must be within the width of the promoted left operand. Do not confuse it with stream insertion.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Left-shift assignment operator (<<=)

The <<= operator shifts the left operand's bits to the left and stores the result in the same object. The left operand is evaluated only once, and the valid shift-count range depends on its type after integral promotion.

Intermediate · C++23; repository compiler flag, production runtime not attested
C++

Less-than-or-equal operator (<=)

The <= operator checks whether its left operand is less than or equal to its right operand. The built-in version returns bool. It is useful for inclusive limits; take care with type conversions and chained comparisons.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Less-than operator (<)

The < operator tests whether its left operand is less than its right operand. A built-in comparison returns bool and excludes equality. Watch for type conversions, restrictions on pointer comparisons, and the misleading chained expression a < b < c.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Logical AND operator (&&)

The built-in && operator produces true only when both conditions are true. It evaluates the left operand first and skips the right operand when the left is false; this is short-circuit evaluation.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Logical negation operator !

The unary operator ! reverses its operand's truth value. The built-in operator contextually converts the operand to bool and returns bool: true for a false value and false for a true value.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Logical OR operator ||

The built-in || operator returns bool: true when at least one operand is true, and false otherwise. It short-circuits: when the left operand is true, the right operand is not evaluated.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Member access operator (.)

The . operator accesses a member of a class, struct, or union object. It lets you read and modify data members and call member functions. It also works through an object reference, but does not replace -> for a pointer.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Multiplication assignment operator (*=)

The *= operator multiplies the left operand’s current value by the right operand and stores the result back. The left operand is evaluated only once, and converting the result to its type can discard a fractional part.

Basic · C++23; repository compiler flag, production runtime not attested
C++

Multiplication operator *

The binary * operator calculates the product of two values. The result type depends on the operand types and the usual arithmetic conversions, not on the destination variable's type. Learn multiplication precedence and the pitfalls of overflow.

Basic · C++23; repository compiler flag, production runtime not attested
C++

new — creating objects and allocating storage

A new-expression creates an object and returns a pointer to it; it usually also obtains storage. Distinguish it from the allocation function operator new, and learn about array new[] and the Placement new-expression that constructs an object in supplied storage.

Intermediate · C++23; repository compiler flag, production runtime not attested
C++

Operator ->: member access through a pointer

The -> operator accesses a data member or calls a member function of the object a pointer points to. For the built-in operator, pointer->member is equivalent to (*pointer).member.

Basic · C++23; repository compiler flag, production runtime not attested
C++

The .* operator and pointer-to-member formation

A pointer to member identifies a class member, not a particular object's member. Form it with &T::member, then apply it to an object with .* or to an object pointer with ->*.

Intermediate · C++23; repository compiler flag, production runtime not attested