Archived

This topic is now archived and is closed to further replies.

using new[] to cre8 multi demensional arays

This topic is 5976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do i use the new[] operator to cre8 a multi dimensional array??? ie int myArray[2][2]; int *myDynamicArray; myDynamicArray = new myDynamicArray[2][2]; //doesnt work ~prevail by daring to fail~

Share this post


Link to post
Share on other sites
Hi

You have to use function malloc

However in this case, won''t help you much
because array[x][x] have special struct

Whatsoever in c/c++ saying somewhere in code (main or WinMain)

int array[2][2]

is already a dynamic reservation,...

I really hope i helped you


Share this post


Link to post
Share on other sites
Try this:

  
int **myDynamicArray = NULL;
int x = 2;
int y = 2;

myDynamicArray = new int * [x];
for(int i = 0;i < x;i++)
{
myDynamicArray[i] = new int [y];
}


hope that helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ITH3 is right,
but may also use this...

int (*myDynamicArray)[2];
myDynamicArray = new float[2][2];

ccc...





Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ITH3 is right,
but may also use this...

int (*myDynamicArray)[2];
myDynamicArray = new int[2][2];

ccc...





Share this post


Link to post
Share on other sites