C memory workbench
Break it. Then understand it.
Two focused labs for the parts of C that are hardest to hold in your head: the pointer chain and bit-level manipulation. Change values, break links, and watch the consequences.
Pointer chain
Every pointer is a box holding an address.
ppint **
0x7ffc1008
0x7ffc1004
pint *
0x7ffc1004
0x7ffc1000
xint
0x7ffc1000
42
pppx**pp is valid
Operate on memory
pointer-chain.cC
int x = 42;
int *p = &x;
int **pp = &p;
/* p stores the address of x */
/* pp stores the address of p */
printf("%d", **pp);Memory log
int x = 42;
int *p = &x;
int **pp = &p;
Pointer arithmetic: walk an array
int is 4 bytes here. Adding 1 to an int pointer advances 4 bytes, not 1.
q points to
0x7ffc2000
*q
10
q + 1 → 0x7ffc2004
*(q + 1) → 20
a[i] ≡ *(a + i)