Simvik

Update a total

Read and write the same variable through a pointer. An easy embedded C problem (A first look at pointers), run and graded in the browser.

easy · A first look at pointers · pointers

Add amount to the variable that total points to.

Starter code

void add_to(int *total, int amount) {
}

Example tests

Add a positive amount

int total = 10;
add_to(&total, 5);
printf("%d\n", total);

Expected output:

15

Add a negative amount

int total = 10;
add_to(&total, -4);
printf("%d\n", total);

Expected output:

6

Learn it first

More A first look at pointers problems