b) Describe how the variables “p” and “list” are related.
c) Add a reverse function that creates an array and returns a pointer to that array. Test your code in the main function.
#include <iostream>
#include <algorithm>
using namespace std;
void printArray(int* const list, int size)
{
for (int i = 0; i < size; i++)
cout << list[i] << ” “;
cout << endl;
}
int main()
{
int list[] = {4, 2, 3, 6, 5, 1};
printArray(list, 6);
int* min = min_element(list, list + 6);
int* max = max_element(list, list + 6);
cout << “The min value is ” << *min << ” at index ”
<< (min – list) << endl;
cout << “The max value is ” << *max << ” at index ”
<< (max – list) << endl;
random_shuffle(list, list + 6);
printArray(list, 6);
sort(list, list + 6);
printArray(list, 6);
int key = 4;
int* p = find(list, list + 6, key);
if (p != list + 6)
cout << “The value ” << *p << ” is found at position ”
<< (p – list) << endl;
else
cout << “The value ” << *p << ” is not found” << endl;
return 0;
}