O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required