3 ms·
I learned pointers by drawing boxes and arrows which I think is the best high-level explanation. Basically a variable is a container which holds a value from a
by augustk 6y ago
I learned pointers by drawing boxes and arrows which I think is the best high-level explanation. Basically a variable is a container which holds a value from a predetermined set of values (also known as a type). For instance, an integer variable x holding the value 37 can be visualized as a box with the name x:
x
+--+
|37|
+--+
A pointer variable p can be visualized as a box which "contains" an arrow pointing to another variable of a certain type, for instance
p x
+--+ +--+
| -|--->|37|
+--+ +--+
which correspond to the C declarations
int x = 37;
int *p = &x;
- bear8642 6y agoAnd that's the way they're shown in K&R2