Lecture 9: Pointers
Intro to pointers
Declaring and using pointers video
Using pointers to pass by reference video
Arrays as pointers video
Segementation fault video
Optional reading: chapter 6
Key ideas:
- What is a pointer?
- Declarations and manipulation of pointers
&
operator: address of*
symbol meanings:- In a variable declaration statement,
*
means “pointer to” - In executable statements,
*
is the indirection operator and means “follow the pointer” *
is also a binary operator (needing two inputs) when we use it to mean multiplication.
- In a variable declaration statement,
- Pass by reference vs. pass by value review
- Equivalence of arrays and pointers
- Pointer arithmetic for arrays
- Why do we use pointers? To pass values by reference, to access arrays effectively, to allocate memory dynamically, and to define complex data structures.