I'm in the process of teaching myself C++ with several books including "Sams...C++ in 21 Days". In the Q&A section of Chapter (Day) 13 of the Sams book ("Managing Arrays and Strings") the authors state that "with simple arrays, you can use pointers to combine them into a new, larger array."
I take this to mean that it is possible to combine numerical arrays (as opposed to strings, where the strcat method can be used).
But I'm unable to locate any specific mention of how to do this in any of my books or online.
This is the code I've started with (which compiles and runs but only gives me access to arrayOne's data through arrayThree):
// combining arrays with pointers
#include <iostream>
using namespace std;
int main()
{
int arrayOne[3]={1,3,5};
int arrayTwo[3]={2,4,6};
int *arrayThree=new int[6];
arrayThree=arrayOne;
cout << arrayThree[2] << endl;
delete[] arrayThree;
return 0;
}
I wonder if anyone have an insight into this question. Thanks for any help you might be able to provide.
Thanks so much for your help; I really appreciate it.
I'll have to spend some time with your first example but I was interested to learn (by your second example) that array elements need to be initialized again when they're re-assigned to a new array (on the heap).