Loading lessons...
C Cheatsheet: Pointers Recap
Cheatsheet: Pointers at a Glance
| Meaning | Code | |
|---|---|---|
int *p | p is a pointer to an int | |
&x | address of x | |
*p | value that p points to | |
p->age | member of a struct pointed to by p | |
NULL | points 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.