Thuta Learning
AdvancedProgrammingbeginner

Memory Address

Relax. We'll talk through this in plain words — no textbook voice.

Every variable takes up a spot in computer memory, and that spot is called a memory address. In C you can actually see the address and store it in a pointer, which lets you study memory directly instead of just taking it on faith.

c
#include <stdio.h>

int main() {
  int myAge = 43;

  printf("Value: %d
", myAge);
  printf("Address: %p", (void *)&myAge);
  return 0;
}

&myAge returns the memory address of the myAge variable. %p is the output format for pointers/addresses.

You should see
Value: 43 Address: 0x7ffe5367e044

Info

The address value can change between computers and between runs, so don't expect your output to match exactly.

Easy traps

  • Don't print an address with the plain integer format %d. Use %p for pointer/address output.
Memory Address | Thuta Learning