Lesson 120 +10 XP

C Cheatsheet: Pointers Recap

Cheatsheet: Pointers at a Glance

MeaningCode
int *pp is a pointer to an int
&xaddress of x
*pvalue that p points to
p->agemember of a struct pointed to by p
NULLpoints nowhere

Flow

int a = 5;
int *p = &a;   // p stores a's address
*p = 7;        // a becomes 7

Arrow for structs

p->age = 30;    // same as (*p).age = 30

TL;DR

  • & takes an address, * follows it.
  • > accesses members through pointers.
  • NULL means pointer nowhere.
  • Check before dereferencing.