change size of an array

Started by
2 comments, last by delbogun 21 years, 7 months ago
If i have a array myArray[5], is it possible to change the size of the array to newArray[10]? I know it''s possible in Java (myArray = newArray)
Advertisement
You can''t do that with built in arrays.
In C++, check out the std::vector class.
In C, look into dynamic allocation using malloc, realloc, free. realloc is a bit dodgy because it can move data about.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
You have to do (for int):

  int myArray[5];int newArray[10];memcpy(newArray, myArray, 5 * sizeof(int));// if you allocated myArray with new then you can delete it now  



schiggl
thanks, that really helped

This topic is closed to new replies.

Advertisement