pointers-memory · beginner · ~3 min
Read a value via dereference.
Read the value of a variable through a pointer to it.
Implement int deref(const int *p) that returns the int value p points to. No main — the grader calls it.
p — a pointer to a valid int (never NULL in the tests).
Returns the int stored at *p.
int x = 7; deref(&x) -> 7
int y = -9; deref(&y) -> -9
Drill: practice one contract before combining it with other skills.
p — a pointer to a valid int (never NULL in the tests).
Returns the int stored at *p.
p points to a live readable int and is never NULL. Return its value without mutation or allocation.
int deref(const int *p) {
/* TODO */
return 0;
}
Returning a constant or trying to return the address instead of the int.
Zero, negatives, integer limits, and different addresses with the same value.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.