Skip to main content

Operations on Pointers in C

The main operations you can perform on pointers:
  1. Pointer Assignment
  2. Dereferencing
  3. Pointer Arithmetic (p++, p--, p+n, p-n)
  4. Pointer to Pointer

a) Pointer Assignment

Store the address of a variable in a pointer:
Assign one pointer to another (both point to the same location):

b) Dereferencing

Access the value stored at the address a pointer holds using *:

c) Pointer Arithmetic

Pointer arithmetic moves the pointer across memory positions based on the data type size. For int *p (assuming int = 4 bytes): p++ moves 4 bytes forward. p++ — next element:
p-- — previous element:
p + n — move forward n elements:
p - n — move backward n elements:

d) Pointer to Pointer (Double Pointer)

A pointer that stores the address of another pointer:
Useful for dynamically allocated 2D arrays and functions that need to modify a pointer itself.