Hi all,
We can see that the result is not what we are expected. Can anyone tell me what need to fix in order to get the correct result using same function? Thanks in advance.
#include <iostream>
#define LENGHT 5
using std::cout;
using std::endl;
int* getArray();
void printArray(int* array);
int main()
{
int* array = getArray();
cout << "array in main" << endl;
printArray(array);
return 0;
}
int* getArray()
{
int array[LENGHT] = {1, 2, 3, 4, 5};
cout << "array in getArray()" << endl;
printArray(array);
return array;
}
void printArray(int* array)
{
for (int i = 0; i < LENGHT; i++)
cout << *(array+i) << " ";
cout << endl;
cout << endl;
}
/*
Output
array in getArray()
1 2 3 4 5
array in main
-858993460 -858993460 -858993460 3 1245056
Press any key to continue
*/