   int** test = new int[100][200]?
  Is it possible to allocate memory for a multi-dimensional array in one line of code?This doesn''t work:int** test = new int[100][200];I''ve been doing it like this:int** test = new int*[100];for (int i = 0; i<100; i++){    test = new int[200];}but i was just wondering if there is any easier way?  
  nope, not as far as I''m aware. You could make a templated function to give you a 2D (or higher) arbitrary sized array but the whole point of 2D arrays declared dynamically is that it''s an array of pointers, each of which is actually an array. So you have to get the array of pointers then assign each one its own array. You can create a 1D array of size width*height and index into it using element(y,x) = array[y*width + x]; this could be done using a special 2D array class to make it more transparent what''s going on. ;  You can always simplify the code, simulating 2Dimensions as follows: int * myArray = new int[length * depth];...myArray[yIndex * depth + xIndex] = ...;// and... = myArray[xPos * depth + xIndex];...where xIndex and yIndex and the access positions. [edit] spelling...   [edited by - superdeveloper on February 17, 2004 10:08:53 AM];  I would recommend a vector of vectors std::vector<std::vector<int> > twod(100, std::vector<int>(200));As for int** test = new int[100][200];, i see no reason why something like this shouldn't work, int[100] is a type afterall.  The return type of the new[] expression will need casting to int** int** test = (int**) new int[100][200]; Edit:  Problably wouldnt be a good idea to do this, test[k][j] = something;  wouldn't work as expected.   [edited by - Jingo on February 17, 2004 11:41:45 AM];  allocate a block of memory and then access it using a wrapper such as boost.multi_arrayquote:Synopsis    The Boost Multidimensional Array Library provides a class template for multidimensional arrays, as well as semantically equivalent adaptors for arrays of contiguous data. The classes in this library implement a common interface, formalized as a generic programming concept. The interface design is in line with the precedent set by the C++ Standard Library containers. Boost MultiArray is a more efficient and convenient way to express N-dimensional arrays than existing alternatives (especially the std::vector> formulation of N-dimensional arrays). The arrays provided by the library may be accessed using the familiar syntax of native C++ arrays. Additional features, such as resizing, reshaping, and creating views are available.  [edited by - petewood on February 17, 2004 11:06:57 AM];  The reason you cannot do something likeint **x = new int[100][100];   is because an array is actually a pointer to the beginning of a memory block.  The word array is just an easy way to say "I have 100 ints right next to each other in memory."  C/C++ added [] to allow easy access to array elements, but they did not implement muliple brackets.So, back to your question.  the code int **x;   actually means that x is a pointer to a pointer - that x points to a location in memory, and that memory location points to another place in memory.  Confused yet?  let me rewrite the code to show what I mean...int *(*x);    [edited by - Onemind on February 17, 2004 11:17:45 AM];quote:Original post by Jingo  As for int** test = new int[100][200];, i see no reason why something like this shouldn''t work, int[100] is a type afterall.No, it isn''t. The type is int[]. Type does not include dimensional information, ever. ;quote:Original post by Oluseyi  quote:Original post by Jingo   As for int** test = new int[100][200];, i see no reason why something like this shouldn''t work, int[100] is a type afterall.No, it isn''t. The type is int[]. Type does not include dimensional information, ever.   quote: 3.9.7 14882The declared type of an array object might be an array of unknown size and therefore be incomplete at one pointin a translation unit and complete later on; the array types at those two points (“array of unknown bound ofT” and “array of N T”) are different types.;  I''m familier with how multi dimensional arrays work... I was just wondering if there was some clever syntax for initialising the whole thing without having to use a bunch of loops (I''ve got a 4D array going so its a bit messy)... And i think squashing the whole thing down into a 1D array would make things even worse, although i guess it might be slightly faster to access... But i''d rather keep it simple, nevermind i''ll leave it as it is... Thanks for the replies anyway. ;  Here you go int (*array)[200]=new int[100][200];array[5][93]=12;...delete [] array;