Loading lessons...
Memory Address
Memory Address
Every variable lives somewhere in memory, and that location has an address. It's how the computer finds the value.
Get an address with &
The & operator gives the memory address of a variable:
int age = 30;
printf("%p", &age);
Output looks like 0x7ffe6f8d47bc - a hex number, the address in memory.
Addresses vary
The exact number depends on the machine and run - it can change between runs. What matters is the idea: each variable has a unique home.
So what's the point?
- It's how
scanfstores your input (that's why you wrote&x). - It leads to pointers, the key to C's power.
- Arrays' "decay" to an address - the array name itself is an address.
TL;DR
&variablereturns the variable's memory address.- Use
%pto print an address in C. - Addresses are hex numbers and vary by run.
- Understanding addresses is step one toward pointers.