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.

Required fields*

3
  • int** b= new int*[w]; Are we not creating a 2d matrix in this case with int pointers w? Commented Jun 15, 2017 at 18:20
  • @Alex: No; you are not creating a 2D matrix. You are creating an array of pointers to int. If you initialize each of those pointers to point to an array of int, then you can treat it more or less as a 2D array — but it still isn't a 2D array (matrix). Commented Jun 15, 2017 at 18:24
  • 1
    @Alex Technically, no. A matrix has a fixed number of rows and columns. The pointers are not initialized, so you need to allocate an array for each one. These sub arrays can be of different sizes. Also, the array of pointers and each array of ints are separate from each other, while a true 2D array is contiguous. Commented Jun 15, 2017 at 18:25