pointers-memory · beginner · ~15 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

Input format

p — a pointer to an int.

Output format

The int value at *p.

Starter code

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

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