104k views
2 votes
What is the output of the following function if the array nums contains the values 1 2 3 4 5 int backwards(int nums[]) { for (x = 4; x >=0; x--) { cout << nums[x] << " "; } return 0; }

1 Answer

2 votes

Answer:

The output of the program is:

5 4 3 2 1

Step-by-step explanation:

The output of the array will be the reverse of the elements in the array since the initial array was 1 2 3 4 5. The function backwards uses a for statement to accomplish this. Starting at index 4 which is the last element, since there are five elements (indexes from 0-4), the for statement prints out the xth element, decreases x by 1 and continues until the condition is no longer true.

User Robert Redmond
by
6.2k points