Help with Practice Exam Problem II - (Arrays)

Hi folks,

This is the second practice problem (#46 out of 50 problems) for my final C++ exam that I'm not clear on how to complete.

The output is "9." If you could please explain (step-by-step) how I can calculate the correct output I would appreciate it.

Here's the problem:

1
2
3
4
5
6
7
8
9
10
int arr[5] = {2, 6, 5, 7, 9};
int la = arr[0];
for (int c = 1; c < 5; c = c + 1)
{
    if (arr[c] > la)
    {
        la = arr[c];
    }
}
cout << la << endl;


What is the output?

Answer

A. 0


B. 2


C. 5


D. 9

Use your own handchecking. Hope this helps. :)
E.g First command : this cmd defines an array which contains 5 elements : 2, 6, 5, 7, 9

Cmd 2 : Copies the first arr element then pastes it (la)
Last edited on
Sorry, but I don't understand. But thanks for your reply. :-)
Topic archived. No new replies allowed.