Please tell me how to create a multi diminsional array using pointer(dynamic array, set size at run time).
thilinam 0 Light Poster
Recommended Answers
Jump to Post— kvprajapati 1,826Declare pointer to pointer variable,
int **ptr;How many one dim arrays?
p=new int*[4];What is the size of each one array?
*(p+0)=new int[3]; *(p+1)=new int[3]; *(p+2)=new int[3]; *(p+3)=new int[3];How to freed allocated memory?
delete []p;
Jump to Post— wildgoose 420I'd recommend a container class where you pass two axis but gets resolved to a single array allocation.
This is only one example of how to solve this!
class IntArray { private: int *pInt; unsigned int nWidth; unsigned int nHeight; public: IntArray( unsigned int w, unsigned …
Jump to Post— WaltP 2,905How to freed allocated memory?
delete []p;Don't you also have to delete each
parray? :icon_wink:If you aren't sure, the answer is yes, delete each array first before deleting
pitself.
Jump to Post— wildgoose 420Each new[] array requires a delete.
So in that other variation, each branch leg has to be deleted first then the backbone.
All 13 Replies
kvprajapati 1,826 Posting Genius Team Colleague
wildgoose 420 Practically a Posting Shark
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
wildgoose 420 Practically a Posting Shark
kvprajapati 1,826 Posting Genius Team Colleague
daviddoria 334 Posting Virtuoso Featured Poster
u8sand 68 Junior Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
u8sand 68 Junior Poster
siddhant3s 1,429 Practically a Posting Shark
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
siddhant3s 1,429 Practically a Posting Shark
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.