3D Memory & References Lab
See how variables connect to objects. Change the values and follow the code one step at a time.
Understand the connection before moving the diagram
A C pointer can store the address of an object. The pointer and the object are different things: changing the pointed-to object does not change the address stored in the pointer. This lab uses symbolic cells, not actual machine addresses. Choose C to explore this example; other language modes explain their own reference rules.
Worked C example: update an integer through a pointer
#include <stdio.h>
int main(void) {
int score = 10;
int *p = &score;
*p = 20;
printf("%d %d\n", score, *p);
return 0;
}
scorestarts at 10.&scoresupplies its address, stored inp.*p = 20writes to the existing integer.- Both reads produce 20, so the output is
20 20.
Save as pointer.c, compile with gcc -std=c11 pointer.c -o pointer, then run ./pointer. The local integer remains alive throughout this example. A null pointer or a pointer to an object whose lifetime has ended must not be dereferenced.
Try it: insert int other = 30; p = &other; before printing. Predict the result.
Show the answer
It prints 20 30. Reassigning p changes which object it points to; it does not undo the earlier update to score. Both local objects are still alive.
In the interactive lab below, change the initial and mutation values, press Apply, and follow the corresponding source. The program is modeled rather than executed in the browser. Read the complete C pointer lesson or browse all visual labs. This reading is in English; the lab controls and explanations offer ten languages.
Memory explorer
Symbolic objects and connections, not physical addresses or a memory layout.
Read memory state as text
Source code ·
GUIDED TRACEThe highlighted instruction matches the current step.