Simvik

Read through a pointer

Follow an address to the value stored there. An easy embedded C problem (A first look at pointers), run and graded in the browser.

easy · A first look at pointers · pointers · dereference

A pointer holds the address of a variable, which is where that variable lives in memory. Putting * in front of a pointer means "the value at that address".

Return the value that p points to.

Starter code

int read_value(const int *p) {
  return 0;
}

Example tests

A positive value

int x = 42;
printf("%d\n", read_value(&x));

Expected output:

42

A negative value

int x = -7;
printf("%d\n", read_value(&x));

Expected output:

-7

Learn it first

More A first look at pointers problems