(checking myself here) when you declare a 2d array, array[x][y], is an array created that has x-1 elements 'along' and y 'down' or are both 0 based hence an array[3][2] will be accesible in the range array[0 thru 2][0 thru 1].
thanks,
(checking myself here) when you declare a 2d array, array[x][y], is an array created that has x-1 elements 'along' and y 'down' or are both 0 based hence an array[3][2] will be accesible in the range array[0 thru 2][0 thru 1].
thanks,
astride a storied past, thats everywhere you are
> or are both 0 based hence an array[3][2] will be accesible in the range array[0 thru 2][0 thru 1].
Yes, like this
crikey, you wasted no time thanks.
astride a storied past, thats everywhere you are
A '2d' Array can come in many shapes sizes and forms. That is one of the most ineficient ones...
The 'best' way to do this is to use a pointer and a little math:
blah *myarray = new blah[sizex*sizey];
myarray[(y*sizex)+x] = wutever;
Hope that helps .
SPH
I also suggest instead of simple arrays using a linked list... but that is far more to talk about... if interested reply or email!
SPH
Another question, does array[x][y] create x arrays of y, or y arrays of x?
>That is one of the most ineficient ones...
Why? Dynamic allocation wasn't mentioned in the original or subsequent posts (until yours). Stack allocation will be quicker.
> Another question, does array[x][y] create x arrays of y, or y arrays of x?
x arrays of y.
> The 'best' way to do this is to use a pointer and a little math:
Which is exactly what the compiler uses when you write [x][y] anyway, so what's your point?
Once you've done a few projects... you will find the [][] sort of static pointer will not work as well as simply doing it yourself...
Don't make bad habbits, this very thing almost wreked one of my projects:
Try dynamic memory allocation here:
char **blah = (char**)new char[x];
*blah = new char[y];
blah[1][1] = (char)6;
you will usually need to set it up for a 'yx' call instead of 'xy', its jsut not a good habbit to 'form'.
SPH
>you will find the [][] sort of static pointer will not work as well as simply doing it yourself...
Why?
>Don't make bad habbits
Thanks for the advice.
howdy,
i'm very confused???
i am writung an app that will include 3 seperate arrays of about 200 objects each. which form do you suggest. pointers and math, linked list or dynamic memory allocation??
the last 2 i have no idea how to do...oh well back to the books.
M.R.