O'Reilly logo

Learn C the Hard Way: A Clear & Direct Introduction To Modern C Programming by Zed A. Shaw

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

Exercise 15. Pointers, Dreaded Pointers

Pointers are famous mystical creatures in C. I’ll attempt to demystify them by teaching you the vocabulary to deal with them. They actually aren’t that complex, but they’re frequently abused in weird ways that make them hard to use. If you avoid the stupid ways to use pointers, then they’re fairly easy.

To demonstrate pointers in a way that we can talk about them, I’ve written a frivolous program that prints a group of people’s ages in three different ways.

ex15.c

 1   #include <stdio.h>  2  3   int main(int argc, char *argv[])  4   {  5       // create two arrays we care about  6       int ages[] = { 23, 43, 12, 89, 2 };  7       char *names[] = {  8           "Alan", "Frank" ...

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