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. If you give a particular pointer variable the name ptr, then 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 bah instead of to pooh */
Now the value of ptr is the address of bah.
To create a pointer variable, ...
Get C Primer Plus®, Third 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.