/ THE IDEA
Memory addresses identify locations, much as numbered positions identify places in a table. A pointer holds such an address. Dereferencing means using the pointer to reach the object there. Copying a pointer normally copies its address value; it does not automatically create another copy of the object being reached. When two paths reach the same object, they are aliases. The shared object can have only one current value even though the program has several ways to reach it. A genuine data copy would instead create another object with an independent value, subject to whatever deeper copying rules the program defines.
THE FORMAL IDEA
p = address of x; q = p → both refer to x
| x = the actual stored object; p and q = pointer variables containing its location. | | The arrow states the resulting relationship. In C-style notation, *p means the object reached by p, not multiplication in that context. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Toy memory map: address 100 stores x = 7; p contains 100; copy p into q. Set *q = 9. Address 100 now stores 9, so reading *p also gives 9. Change only the setup: q points to a separate copy y at address 200. Set *q = 9; now y is 9 while x, reached through p, remains 7.
|
The different outcome came from changing the relationship between objects, not the assignment operation. A diagram showing two arrows meeting at one box tells you more than two variable names do. Names that look independent can still reach the same mutable information.
/ SO WHAT?
The shortcut comparison has a limit: program memory can be released and reused while an old pointer still exists. Keeping an address does not by itself keep the object valid. A program must obey the language’s lifetime rules and only follow pointers that are valid for the object and operation involved.
ONE CAVEAT |
| Addresses 100 and 200 are invented labels, not locations to use in a real program. Some languages expose references with stronger safety checks instead of unrestricted pointers, and pointer representations are implementation-dependent. |
KEEP THIS
Copying an address preserves sharing; creating an independent object is what separates later changes.
|
NEXT: Why a soft catch can need less force
|