Pointer Basics in C

From the C cheat sheet · Pointers · verified Jul 2026

Pointer Basics

Address-of, dereference, and arithmetic.

c
// Quick Reference
int n = 5;
int *p = &n;     // p holds the address of n
*p = 10;         // dereference: n is now 10
int *q = nullptr; // C23 (or NULL)
💡 & takes an address; * dereferences a pointer to read/write the pointed-to value.
⚡ Dereferencing NULL or an uninitialized pointer is undefined behavior - always init.
📌 Pointer arithmetic advances by sizeof(*p), not by bytes - p+1 skips one element.
🟢 Use nullptr in C23 (or NULL); a plain 0 works but reads less clearly.
pointers

More C tasks

Back to the full C cheat sheet