Pointers
A pointer stores a memory address — the key to arrays, dynamic memory and hardware registers in C.
Intermediate
int value = 42;
int *p = &value; // p holds the address of value
*p = 50; // dereference: value is now 50
&x— "address of x".*p— "the value at address p".NULL— a pointer that points nowhere.
Pointers let functions modify their arguments, let you walk through arrays efficiently and are how C accesses memory-mapped hardware registers.
Sub-topics (4)
Pointer Arithmetic
Adding n to a pointer moves it by n elements, not n bytes.
Intermediate♥ 0🔖 0💬 0
Pointers and Arrays
An array's name decays to a pointer to its first element — but arrays and pointers are not the same thing.
Intermediate♥ 0🔖 0💬 0
Function Pointers
Store the address of a function in a variable — for callbacks, state machines and interrupt tables.
Advanced♥ 0🔖 0💬 0
Dangling and NULL Pointers
A NULL pointer points nowhere; a dangling pointer points to memory that is no longer valid.
Intermediate♥ 0🔖 0💬 0
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.