Simvik

Write through a pointer

Change a variable that belongs to the caller. An easy embedded C problem (A first look at pointers), run and graded in the browser.

easy · A first look at pointers · pointers · out-parameters

A function receives copies of its arguments, so it cannot change the caller's variables directly. Given the address of a variable, it can.

Set the variable that p points to to 0.

Starter code

void set_to_zero(int *p) {
}

Example tests

Clears the variable

int x = 5;
set_to_zero(&x);
printf("%d\n", x);

Expected output:

0

A negative starting value

int x = -100;
set_to_zero(&x);
printf("%d\n", x);

Expected output:

0

Learn it first

More A first look at pointers problems