C Memory Address
Memory Address
When a variable is created in C, its value is stored somewhere in the computer's memory.
The memory address is the location of where the variable is stored.
To get the memory address of a variable, use the reference operator (&), and print it with the %p format specifier:
Note: The memory address is in hexadecimal form (0x..). You will probably not get the same result in your program, as this depends on where the variable is stored on your computer.
You can think of the memory as a long row of boxes, where each box has its own address. myAge gives the value in the box, and &myAge gives the address of the box:
Tip: You have already used the & operator in the User Input chapter: scanf("%d", &myNum). It gives scanf() the memory address of myNum, so it knows where to store the number that the user types.
A variable that stores a memory address is called a pointer. Pointers let you work directly with the data in the computer's memory, and they are one of the things that make C stand out from other programming languages, like Python and Java.
You will learn much more about pointers in the next chapter.