I am sort of new to C++. I am used to programming in Java. This particular problem is causing me great issues, because C++ is not acting like Java when it is dealing with Ar
There are two places in memory that variables can go: the stack and the heap. The stack contains local variables created in methods. The heap holds other variables upon other conditions, like static variables.
When you create a in GetArray() that was a local variable stored on the stack and a was a pointer to that location. When the method returned the pointer, that layer of the stack was released (including the actual values that the pointer was pointing to).
Instead, you need to dynamically allocate the array, then the values will be in the heap which is not cleared when a function returns and a will point to them there.
int * GetArray() {
int* a = new int[3];
a[0] = 1;
a[1] = 2;
a[2] = 3;
cout << endl << "Verifying 1" << endl;
for (int ctr = 0; ctr < 3; ctr++)
cout << a[ctr] << endl;
return a;
}
Now you're passing around the address of those ints to and from functions while the values all sit in the heap where they aren't released until the end of the program or (preferably) you delete them.