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
Dynamic memory allocation for arrays
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.
// 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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement