Defined Terms
C-style stringsC programs treat pointers to null-terminated character arrays as strings. In C++, string literals are C-style strings. The C library defines a set of functions that operate on such strings, which C++ makes available in the cstring header. C++ programs should use C++ library strings in preference to C-style strings, which are inherently error-prone. A sizeable majority of security holes in networked programs are due to bugs related to using C-style strings and arrays.
compiler extensionFeature that is added to the language by a particular compiler. Programs that rely on compiler extensions cannot be moved easily to other compilers.
compound typeType that is defined in terms of another type. Arrays, pointers, and references are compound types.
const void*A pointer type that can point to any const type. See void*.
delete expressionA delete expression frees memory that was allocated by new:
where p must be a pointer to the first element in a dynamically allocated array. The bracket pair is essential: It indicates to the compiler that the pointer points at an array, not at a single object. In C++ programs, delete replaces the use of the C library free function.
delete [] p;
dimensionThe size of an array.
dynamically allocatedAn object that is allocated on the program's free store. Objects allocated on the free store exist until they are explicitly deleted.
free storeMemory pool available to a program to hold dynamically allocated objects.
heapSynonym for free store.
new expressionAllocates dynamic memory. We allocate an array of n elements as follows:
The array holds elements of the indicated type. new returns a pointer to the first element in the array. C++ programs use new in place of the C library malloc function.
new type[n];
pointerAn object that holds the address of an object.
pointer arithmeticThe arithmetic operations that can be applied to pointers. An integral type can be added to or subtracted from a pointer, resulting in a pointer positioned that many elements ahead or behind the original pointer. Two pointers can be subtracted, yielding the difference between the pointers. Pointer arithmetic is valid only on pointers that denote elements in the same array or an element one past the end of that array.
precedenceDefines the order in which operands are grouped with operators in a compound expression.
ptrdiff_tMachine-dependent signed integral type defined in cstddef header that is large enough to hold the difference between two pointers into the largest possible array.
size_tMachine-dependent unsigned integral type defined in cstddef header that is large enough to hold the size of the largest possible array.
* operatorDereferencing a pointer yields the object to which the pointer points. The dereference operator returns an lvalue; we may assign to the value returned from the dereference operator, which has the effect of assigning a new value to the underlying element.
++ operatorWhen used with a pointer, the increment operator "adds one" by moving the pointer to refer to the next element in an array.
[] operatorThe subscript operator takes two operands: a pointer to an element of an array and an index. Its result is the element that is offset from the pointer by the index. Indices count from zerothe first element in an array is element 0, and the last is element size of the array minus 1. The subscript operator returns an lvalue; we may use a subscript as the left-hand operand of an assignment, which has the effect of assigning a new value to the indexed element.
& operatorThe address-of operator. Takes a single argument that must be an lvalue. Yields the address in memory of that object.
void*A pointer type that can point to any nonconst type. Only limited operations are permitted on void* pointers. They can be passed or returned from functions and they can be compared with other pointers. They may not be dereferenced.