master gamer
last year
Mastercountry asked

Why does the order matter when writing &number and pt? I wrote &number = pt; and it didn’t work, but the opposite did. Why?

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Great question — and yes, in C, the order definitely matters when you're working with pointers.

Let’s break it down:

  • &number means “the address of number

  • pt is a pointer that’s supposed to store that address

So when you write:

pt = &number;  // ✅ Correct

You’re saying: “Assign the address of number to the pointer pt.”

But writing:

&number = pt;  // ❌ Invalid

doesn’t make sense to the compiler. You’re trying to assign a value to an address, which isn’t allowed. In C, you can store an address in a pointer, but you can’t overwrite a memory address like that.

So always think of it this way:

A pointer holds the address — it doesn’t assign to it.

If you have more questions, I am here to help.

C
This question was asked as part of the Learn C Programming course.