Chapter 11. Pointers
This chapter covers
- Introduction to pointer operations
- Using pointers with structs, arrays, and functions
Pointers are the first real hurdle to a deeper understanding of C. They are used in contexts where we have to be able to access objects from different points in the code, or where data is structured dynamically on the fly.
The confusion of inexperienced programmers between pointers and arrays is notorious, so be warned that you might encounter difficulties in getting the terms correct. On the other hand, pointers are one of the most important features of C. They are a big plus to help us abstract from the bits and odds of a particular platform and enable us to write portable code. So please, equip yourself with patience when you work through this chapter, because it is crucial for the understanding of most of the rest of this book.
The term pointerC stands for a special derived type construct that “points” or “refers” to something. We have seen the syntax for this construct, a type (the referenced typeC) that is followed by a * character. For example, p0 is a pointer to a double:
double* p0; !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}]]"} !@%STYLE%@!
The idea is that we have one variable (the pointer) that points to the memory of another object:
