Double pointers
Introduction / Definition
A double pointer stores the address of another pointer and is common in C/C++ linked-list manipulation. It is useful when a function must change the caller's pointer itself. Java does not expose raw pointers, so similar behavior is usually achieved with references, wrapper objects, or return values.
Syntax / Structure / Formula
T** p → p points to a T*
Detailed Explanation
Changing the pointer through the double pointer can update the caller's head pointer. This is useful when inserting into an empty or head position.
Example
Example: insertHead(Node\*\* head, x) can update the caller's head.
Output / Result
The caller's head points to the newly inserted node.
Important Points / Notes
- Common in C/C++.
- Do not confuse pointer-to-pointer with pointer-to-object.
Mini Practice Question
Why can linked-list insertion require a double pointer in C?