Hi,
I''ve got a function that returns an array of 2 ints. When I check the array in the function it displays the values correctly. When I call the function and display the 2 values then, I get wrong data. The first value is correct, but the seconds seems to resemble an address. Maybe I did something wrong?
#include <iostream>
using namespace std;
int *test() {
int values[] = {1, 1};
cout << values[0] << ", " << values[1] << endl; // displays 1,1
return values; // return &values[0] gives the same error
}
int main(int argc, char* argv[]) {
int* f = test();
cout << f[0] << ", " << f[1] << endl;
cin.get();
return 0;
}
Outcome :
Does anyone see the problem?