pointers-memory · beginner · ~15 min
Write through an array pointer.
Set every element of an array to the same value, writing through the array pointer.
Implement void fill(int *a, int n, int v) that sets the first n elements of a to v. No main — the grader calls it.
a — pointer to an int array. n — number of elements to set (may be 0). v — the value to write.
No return value. The first n elements of a become v.
int a[4] = {1,2,3,4}; fill(a, 4, 9) -> a == {9,9,9,9}
int b[3] = {5,5,5}; fill(b, 0, 0) -> b unchanged
n == 0: writes nothing.a — int array; n — count to fill (may be 0); v — value.
No return value; the first n elements are set to v.
void fill(int *a, int n, int v) {
/* TODO */
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.