Question: Consider the following function reverse, that attempts to reverse an array in place (i.e. without the use of additional storage). It does it by interchanging

Consider the following function reverse, that attempts to reverse an array in place (i.e. without the use of additional storage). It does it by interchanging the first and last elements, then the second and second from last etc. All of the interchanges are done by calling function interchange. Here are the two functions and a main program:

(SEE ATTACHMENT)Consider the following function reverse, that attempts to reverse an array in

  1. When I run the program, I expect to see the output reverse the array, but it doesnt. Why?

  2. What very simple change will fix it (so the program will print 3, 2, 1, ) and explain your change.

#include using namespace std; void interchange (int* x, int* y) { int temp; temp = *X; *x = *y; *y = temp; } = void reverse(int *ptr, int first, int last) { int *endptr; endptr ptr + last; for ( ptr += first; ptr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!