so I was presented with this code and I get most of it up until it's supposed to assign a pointer to an array. The object is to assignment is to have to program print out 100 99 98 3 2 1. So it seemed to me like function f does nothing so I deleted it. My question is how do I assign the pointer to the array within the function? I also thought returning the array would work but that didn't work out. Thanks in advance
#include <iostream>
using namespace std;
int* nochange(int* p)
{
return p;
}
int* getPtrToArray(int& m)
{
int anArray[100];
for (int j = 0; j < 100; j++)
anArray[j] = 100-j;
m = 100;
return nochange(anArray);
}
void f()
{
int junk[100];
for (int k = 0; k < 100; k++)
junk[k] = 123400000 + k;
junk[50]++;
}
int main()
{
int n;
int* ptr = getPtrToArray(n);
f();
for (int i = 0; i < 3; i++)
cout << ptr[i] << ' ';
for (int i = n-3; i < n; i++)
cout << ptr[i] << ' ';
cout << endl;
}c