pointers-memory · beginner · ~3 min

Read through a pointer

Read a value via dereference.

Challenge

Read the value of a variable through a pointer to it.

Task

Implement int deref(const int *p) that returns the int value p points to. No main — the grader calls it.

Input

p — a pointer to a valid int (never NULL in the tests).

Output

Returns the int stored at *p.

Example

int x = 7; deref(&x)    ->   7
int y = -9; deref(&y)   ->   -9

Why this matters

Drill: practice one contract before combining it with other skills.

Input format

p — a pointer to a valid int (never NULL in the tests).

Output format

Returns the int stored at *p.

Constraints

p points to a live readable int and is never NULL. Return its value without mutation or allocation.

Starter code

int deref(const int *p) {
    /* TODO */
    return 0;
}

Common mistakes

Returning a constant or trying to return the address instead of the int.

Edge cases to handle

Zero, negatives, integer limits, and different addresses with the same value.

Up next

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.