pointers-memory · beginner · ~4 min
Write through a pointer with the dereference operator.
Write a value into a variable that lives in the caller, given only a pointer to it.
Implement void set_via_ptr(int *p, int v) that stores v into the int that p points to. No main — the grader calls it.
p — a pointer to a caller int. v — the value to store.
No return value. After the call, the int at *p equals v.
int x = 0; set_via_ptr(&x, 42) -> x == 42
Drill: practice one contract before combining it with other skills.
p — a pointer to a caller int. v — the value to store.
No return value. After the call, the int at *p equals v.
p points to a live writable int; p is never NULL. Write only that int. No allocation or ownership transfer.
void set_via_ptr(int *p, int v) {
/* TODO */
}
Assigning to the local pointer rather than its target; changing a neighboring int.
Zero, negative values, INT_MIN/INT_MAX, repeated writes, and a pointer into an array must work without changing neighbors.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.