Pointers
Memory addresses, pointer syntax, null pointers, array decay, pointer arithmetic, const-correctness, and common pointer lifetime errors.
Memory Addresses and Pointers
Any object in memory that is active when your program is running has a location, called its address. You can use C++ to get the address of an object and have yo…
Address-of and Dereference Operators
Let's discuss the two operators we have that use addresses, them being & and *. One of them finds the address of something and the other reads the thing at the…
Null Pointers and nullptr
A pointer can contain an address, but there is not always an object for it to point to. In this case, the pointer needs to be assigned a special value that says…
Passing Pointers to Functions
When a function wants to access an existing object in the caller, one clear way is to pass the address of the object. The function setToZero takes a pointer cal…
Pointers and Arrays
An array name and a pointer to its first element can be used in almost the same way. That is part of the language. We've declared an array scores of 4 integers.…
Passing Arrays to Functions and Understanding Array Decay
Something subtle but important happens when an array is passed to a function: the array decays to a pointer to its first element. This process is called array d…
Pointer Arithmetic
Pointer arithmetic means adding an integer to a pointer, which moves the pointer that number of element sizes forward. An array of ints named values is declared…
Const Pointers and Pointers to Const
A const qualifier can appear in two different locations relative to the * in a pointer declaration. These two locations have completely different semantics. Dec…
const_cast and Const-Correctness
Const correct code is where objects that are not intended to be modified are marked as const, and the compiler then enforces that "promise." An old interface or…