Pointers: A First Look
Pointers? What are they? Basically, a pointer is a variable (or, more generally, a data object) whose value is an address. Just as a char variable has a character as a value and an int variable has an integer as a value, the pointer variable has an address as a value. Pointers have many uses in C; in this chapter, we'll see how and why they are used as function parameters.
If you give a particular pointer variable the name ptr, you can have statements like the following:
ptr = &pooh; /* assigns pooh's address to ptr */
We say that ptr “points to” pooh. The difference between ptr and &pooh is that ptr is a variable, and &pooh is a constant. If you want, you can make ptr point elsewhere:
ptr = &bah; /* make ptr point to ...
Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.