side effect problem!

Hi i was wondering if someone could try to explain this function to me(doesnt have to be to in depth, i just dont really understand it), and what the side effect is, and what it does thanks!

int Max (/* in */ int trio[3])
{
int temp;
if (trio[0] > trio[1])
{
temp = trio[1];
trio[1] = trio[0];
trio[0] = temp;
}

if (trio[1] > trio[2])
{
temp = trio[2];
trio[2] = trio[1];
trio[1] = temp;
}

return trio[2];
}
It takes three integers, sorts them, and returns the largest.

Try tracing through the code to see it work.

Hope this helps.
k and why does it return trio[2], like what does that mean?
It returns the value of trio[2] to where ever you called the function from.
it returns trio[2] because when the function ends, trio[2] will always have the maximum value.
You need to hit the books some more.

C++ Language Tutorial
http://www.cplusplus.com/doc/tutorial/

Arrays
http://www.cplusplus.com/doc/tutorial/arrays.html

Good luck!
k thanks a bunch! much appreciated!
Topic archived. No new replies allowed.