pointers-memory · beginner · ~15 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
p (pointer to an int) and the value v.
No return value; *p is set to v.
void set_via_ptr(int *p, int v) {
/* TODO */
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.