CMD Simulator

Pointers in C - Addresses and Dereferencing

Understand pointers, the address-of operator (&), and dereferencing (*) in C.

Pointers in C

A pointer is a variable that holds the address of another variable.

Address-of (&)

The & operator returns the memory address of a variable:

int x = 5;
int* p = &x;  // p now holds the address of x

Dereference (*)

The * operator accesses the value at the address stored in a pointer:

*p = 10;  // x is now 10

Why Pointers Matter

  • Pass large data by reference (avoid copying)
  • Dynamic memory allocation (malloc)
  • Implement data structures (linked lists, trees)