Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 74
    It only works if sizeX is constant: int(*ary)[sizeX] = new int[sizeY][sizeX]; Which is the right way to create a int[sizeY][sizeX] and where all the memory is contiguous. (I don't think this is worth an answer, since probably your sizeX is not constant Commented Jun 1, 2009 at 20:49
  • 36
    I can't belive all the dozen of answers below are all wrong and doesn't answer the question, and yet they are all upvoted. The above comment by Johanes Shaub is the only correct answer to the question. A 2D array and an array of pointer to array are two completely separate things, that apparently everyone mixes up.
    – Bregalad
    Commented Mar 15, 2015 at 9:09
  • 8
    @JohannesSchaub-litb: That's not 100% correct. Certainly it does work in that case, but there's a method to make it work where all dimensions vary, see stackoverflow.com/a/29375830/103167
    – Ben Voigt
    Commented Mar 31, 2015 at 19:42