logo CodeStepByStep logo

mystery2

Language/Type: C++ arrays

Consider the following function:

void mystery2(int a[], int length) {
    for (int i = 1; i < length - 1; i++) {
        a[i] = a[i - 1] - a[i] + a[i + 1];
    }
}

Indicate in the right-hand column what values would be stored in the array after the function arrayMystery executes if each integer array below is passed as a parameter to it.

int a1[] = {42, 42}; mystery2(a1, 2);
int a2[] = {6, 2, 4}; mystery2(a2, 3);
int a3[] = {7, 7, 3, 8, 2}; mystery2(a3, 5);
int a4[] = {4, 2, 3, 1, 2, 5}; mystery2(a4, 6);
int a5[] = {6, 0, -1, 3, 5, 0, -3}; mystery2(a5, 7);

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.