0

I got stuck :(. Can anyone tell me the purpose of this following code please? (Suggest descriptive names for the function and its parameters.)

int mystery(int x, int y[], int z) {
for (int i = 0; i < z; i++) {
if (y[i] == x) return i;
}
return -1;
}

thank you so much.

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by WaltP
1

returns the index where the current element of array y is equal to x, else returns -1 if the value of x is not in the array

Edited by zeroliken

0

By the way, could you help me with this as well? this is the question:
what will print for a[], p, q after line 2, 3, 4 and 5? I have done for line 1, then I got stuck :(.

int a[] = { 0, 1, 2, 3, 4, 5, 6 };
int* p;
int* q;
p = a; q = p; *q = 6; // line 1
(*q)++; q++; (*q)++; // line 2
p = ++q; ++p; *p = 7; // line 3
*q = *p; // line 4
p[1] = q[-1]; // line 5

thanks

0

what will print

Nothing. There are no output statements.

Assuming that's not the correct answer, sit down with pen and paper and figure it out.

Write down the variables and their contents
Write down the pointers and where they point
Now follow the code statement by statement

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.