codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › C pointers

C pointers

Variables that hold addresses.

Declare with *. p = &x stores an address; *p reads or changes the value there (dereference). Arrays decay to pointers.

Example code

#include <stdio.h>
int main() {
  int x = 5, *p = &x;
  *p = 9;
  printf("%d %d\n", x, *p);
  int a[] = {1, 2, 3};
  printf("%d\n", *(a + 2));
  return 0;
}

Run this code in the online editor

← C memory addressC functions →