PDA

Click to See Complete Forum and Search --> : empty array


hyper88
Apr 5th, 2002, 09:00 AM
how do i declare a 2D array which is empty?

like int array[][];

then then i can decide on the number of rows and cols based on what the user given

and how do i write function for a 2D array

void array(int array[][] ) ???
or
void array(int array[row][col] , int row , int col)

??

Technocrat
Apr 5th, 2002, 12:40 PM
There is two ways to do this (FYI its called dynamically declared array).

The easiest way is to used linked list, which if you search this form you are bound to find alots of examples for.

The other way is to use new and delete to make a new array and to delete it. The hard part about doing it this way is you have to move the data out of your array delete it, resize it making using new, copy the data back, then delete your temp array. Again if you search this for you should find examples.