Advertisement

Dynamic memory allocation for arrays

Started by January 15, 2000 06:40 AM
0 comments, last by LackOfKnack 25 years, 1 month ago
Hey! I''m not very good at C++ yet, so I have a newbie question: How do you dynamically allocate memory for a two-dimensional array? I''m using BTC++ 3 for DOS for now. I had something like: int *table[][]; ... malloc whatever; It doesn''t seem to work very well. Any suggestions? Thanks.
Lack
Lack
Christianity, Creation, metric, Dvorak, and BeOS for all!
With C++, don''t forget the new and delete keywords. Try this.

// Pointer To The Array
int* pArray;

// Allocate The Array (You Don''t Have To Use Constants)
pArray = new int[3][3];

...

delete [] pArray;

In case you don''t know, the "[]" after delete lets the compiler knoew that you want to free the array, not just an int.

Hope this helps.

This topic is closed to new replies.

Advertisement