O'Reilly logo

Head First C by Dawn Griffiths, David Griffiths

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

Chapter 2. Memory and Pointers: What are you pointing at?

image with no caption

If you really want to kick butt with C, you need to understand how C handles memory.

The C language gives you a lot more control over how your program uses the computer’s memory. In this chapter, you’ll strip back the covers and see exactly what happens when you read and write variables. You’ll learn how arrays work, how to avoid some nasty memory SNAFUs, and most of all, you’ll see how mastering pointers and memory addressing is key to becoming a kick-ass C programmer.

C code includes pointers

Pointers are one of the most fundamental things to understand in the C programming language. So what’s a pointer? A pointer is just the address of a piece of data in memory.

Pointers are used in C for a couple of reasons.

To best understand pointers, go slowly.

  1. Instead of passing around a whole copy of the data, you can just pass a pointer.

    image with no caption
  2. You might want two pieces of code to work on the same piece of data rather than a separate copy.

    image with no caption

Pointers help you do both these things: avoid copies and share data. But if pointers are just addresses, why do some people find them confusing? Because they’re a form of indirection. If you’re not careful, you can ...

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