I am trying to pass an int array around. Below is an example of what I want to do. Basically, I can write a function that returns an int array by returning a pointer. Now I want to take that function and use it as an argument to another function. The goal is to have one function create an int array and then this goes into another function that takes an int array as an input. It doesn't work. Inside the function that takes the int * pointer, the int * pointer just becomes -8435432 and can't have its elements read after it is assigned to another int * pointer. I don't get it. Why can I get an int array back from a function but this can't then be used as an input to another function?
int * returnIntArray()
{
int * thePointer;
int j[3];
thePointer = j;
j[0] = 1;
j[1] = 3;
j[2] = -1;
return thePointer;
}
//
int * takesTheIntArray(int * anIntArray)
{
int x,y,z;
int * returnIt;
returnIt = anIntArray;
x = returnIt[0];
y = returnIt[1];
z = returnIt[3];
return returnIt;
}
int _tmain(int argc, _TCHAR* argv[])
{
int y,z,p;
int * x;
x = returnIntArray();
y = x[0];
z = x[1];
x = takesTheIntArray(returnIntArray());
cout << x[0] << ", " << x[1];
//cout << theVector[1];
cout << "hello";
}