Simvik

Fill an array

Write to the elements of an array. An easy embedded C problem (Arrays and text), run and graded in the browser.

easy · Arrays and text · arrays · writing

Set each of the first n elements of values to value.

The function changes the caller's array directly. An array is not copied when it is passed to a function.

Starter code

void fill(int values[], int n, int value) {
}

Example tests

Fill everything

int v[4] = { 1, 2, 3, 4 };
fill(v, 4, 7);
printf("%d %d %d %d\n", v[0], v[1], v[2], v[3]);

Expected output:

7 7 7 7

Fill only the first two

int v[4] = { 1, 2, 3, 4 };
fill(v, 2, 0);
printf("%d %d %d %d\n", v[0], v[1], v[2], v[3]);

Expected output:

0 0 3 4

Learn it first

  • Arrays and text · Many values under one name, looping over them safely, and strings.

More Arrays and text problems