Pointers
Pointers allow us to access addresses in memory, and what is inside of those addresses, instead of just values. In C, all variables passed to a function are passed by reference, or only as copies of their value. Passing pointers instead of values allows us to change multiple variables (see the swap example in Rob’s short below) where before we could only return one value. In this section, we will discuss the basics of pointers and their operators (* and &), which will become a key piece of the foundation for the remaining C programs in the course.
-
Lecture
-
Shorts
-
Supplementary Resources
- Puneet Sapra on No more fear of pointers
- Stanford CS on Pointer Fun with Binky
-
Thought Questions
- What are the advantages of being able to access addresses in memory?
- What are the dangers of using pointers?
- If pointers are so great, why do we ever pass by value?