Chapter 2. Memory and Pointers: What are you pointing at?
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.
Instead of passing around a whole copy of the data, you can just pass a pointer.
You might want two pieces of code to work on the same piece of data rather than a separate copy.
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 ...
Get Head First C 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.