How Multiple Pointers Reference a Single Address in C

3

C lets you create a crowd around a single memory location. You don’t have to settle for one pointer. Any number of pointers can point to the same address. This isn’t a bug. It’s a feature of how C handles memory references.

Consider a simple integer variable i. You can declare three distinct pointers: p, q, and r. The code is straightforward.

Look at that last line. r points to the same thing that p points to. And since p is already assigned the address of i, r is effectively pointing at i too.

The assignment operator copies the address from the right-hand side to the left-hand side. It doesn’t copy the value stored at that address. It copies the location itself. This is a key distinction in pointer arithmetic.

After execution, i has four names. You can refer to the integer as i. You can modify it via *p. You can read it through *q. You can also access it using *r.

There is no limit to how many pointers can hold the same address. You could declare s, t, and u if you wanted. They would all just be aliases for the same piece of memory.

This flexibility matters. It allows functions to share references to data without copying large structures. It enables complex data structures where multiple nodes point to the same child. It makes managing resources in C more efficient.

But it also introduces risk. If one pointer modifies the value, all pointers see the change. There’s no isolation. You have to be careful. One pointer changes the integer. The others see it immediately.

The variable i now has four names: i, *p, *q, and *r.

This is basic pointer arithmetic. It’s fundamental to understanding C memory models. But it’s also where things get tricky. Multiple references to the same address mean multiple ways to corrupt data.

You can chain pointer assignments endlessly. s = r; t = s;. It all points back to i. The compiler doesn’t care. The runtime doesn’t care. It’s just memory addresses.

Why does this matter for everyday users? If you’re writing C code, you rely on this. If you’re debugging a crash, this is often the culprit. Use-after-free errors thrive in environments where pointers are reassigned but not nullified.

The efficiency comes at a cost. Complexity. You have to track who owns the data. Who is allowed to modify it. With multiple pointers, that tracking becomes harder.

But the power is undeniable. You can pass pointers to functions. Change the value. The original variable reflects the change. It’s how C achieves reference semantics without objects.

It’s a simple concept. Copy the address. Don’t copy the value. Let multiple names refer to one location. Use it wisely.