Defined Terms
- arithmetic conversion
A conversion from one arithmetic type to another. In the context of the binary arithmetic operators, arithmetic conversions usually attempt to preserve precision by converting a smaller type to a larger type (e.g., small integral types, such as char and short, are converted to int).
- associativity
Determines how operators of the same precedence are grouped. Operators can be either right associative (operators are grouped from right to left) or left associative (operators are grouped from left to right).
- binary operators
Operators that take two operands.
- cast
An explicit conversion.
- compound expression
An expression involving more than one operator.
- const_cast
A cast that converts a const object to the corresponding nonconst type.
- conversion
Process whereby a value of one type is transformed into a value of another type. The language defines conversions among the built-in types. Conversions to and from class types are also possible.
- dangling pointer
A pointer that refers to memory that once had an object but no longer does. Dangling pointers are the source of program errors that are quite difficult to detect.
- delete expression
A delete expression frees memory that was allocated by new. There are two forms of delete:
delete p; // delete object
delete [] p; // delete array
In the first case, p must be a pointer to a dynamically allocated object; in the second, p must point to the first element in a dynamically allocated array. In C++ programs, delete replaces the use of the C library free function.
- dynamic_cast
Used in combination with inheritance and run-time type identification. See Section 18.2 (p. 772).
- expression
The lowest level of computation in a C++ program. Expressions generally apply an operator to one or more operands. Each expression yields a result. Expressions can be used as operands, so we can write compound expressions requiring the evaluation of multiple operators.
- implicit conversion
A conversion that is automatically generated by the compiler. Given an expression that needs a particular type but has an operand of a differing type, the compiler will automatically convert the operand to the desired type if an appropriate conversion exists.
- integral promotions
Subset of the standard conversions that take a smaller integral type to its most closely related larger type. Integral types (e.g. short, char, etc.) are promoted to int or unsigned int.
- new expression
A new expression allocates memory at run time from the free store. This chapter looked at the form that allocates a single object:
new type;
new type(inits);
allocates an object of the indicated type and optionally initializes that object using the initializers in inits. Returns a pointer to the object. In C++ programs, new replaces use of the C library malloc function.
- operands
Values on which an expression
- operator
Symbol that determines what action an expression performs. The language defines a set of operators and what those operators mean when applied to values of built-in type. The language also defines the precedence and associativity of each operator and specifies how many operands each operator takes. Operators may be overloaded and applied to values of class type.
- operator overloading
The ability to redefine an operator to apply to class types. We'll see in Chapter 14 how to define overloaded versions of operators.
- order of evaluation
Order, if any, in which the operands to an operator are evaluated. In most cases in C++ the compiler is free to evaluate operands in any order.
- precedence
Defines the order in which different operators in a compound expression are grouped. Operators with higher precedence are grouped more tightly than operators with lower precedence.
- reinterpret_cast
Interprets the contents of the operand as a different type. Inherently machine-dependent and dangerous.
- result
The value or object obtained by evaluating an expression.
- static_cast
An explicit request for a type conversion that the compiler would do implicitly. Often used to override an implicit conversion that the compiler would otherwise perform.
- unary operators
Operators that take a single operand.
- ~ operator
The bitwise NOT operator. Inverts the bits of its operand.
- , operator
The comma operator. Expressions separated by a comma are evaluated left to right. Result of a comma expression is the value of the right-most expression.
- ?: operator
The conditional operator. If-then-else expression of the form: operates.
cond ? expr1 : expr2;
If the condition cond is true then expr1 is evaluated. Otherwise, expr2 is evaluated.
- & operator
Bitwise AND operator. Generates a new integral value in which each bit position is 1 if both operands have a 1 in that position; otherwise the bit is 0.
- ^ operator
The bitwise exclusive or operator. Generates a new integral value in which each bit position is 1 if either but not both operands contain a 1 in that bit position; otherwise, the bit is 0.
- | operator
The bitwise OR operator. Generates a new integral value in which each bit position is 1 if either operand has a 1 in that position; otherwise the bit is 0.
- ++ operator
The increment operator. The increment operator has two forms, prefix and postfix. Prefix increment yields an lvalue. It adds one to the operand and returns the changed value of the operand. Postfix increment yields an rvalue. It adds one to the operand and returns the original, unchanged value of the operand.
- -- operator
The decrement operator. has two forms, prefix and postfix. Prefix decrement yields an lvalue. It subtracts one from the operand and returns the changed value of the operand. Postfix decrement yields an rvalue. It subtracts one from the operand and returns the original, unchanged value of the operand.
- << operator
The left-shift operator. Shifts bits in the left-hand operand to the left. Shifts as many bits as indicated by the right-hand operand. The right-hand operand must be zero or positive and strictly less than the number of bits in the left-hand operand.
- >> operator
The right-shift operator. Like the left-shift operator except that bits are shifted to the right. The right-hand operand must be zero or positive and strictly less than the number of bits in the left-hand operand.
|