Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While all these answers are relevant, I will try to explain what came to an expectation, that something like <em><code>delete[][] array;</code></em> may work on dynamically allocated arrays and why it's not possible:</p> <p>The syntax <code>int array[ROWS][COLS];</code> allowed on <strong>statically</strong> allocated arrays is just abstraction for programmers, which in reality creates one-dimensional array <code>int array[ROWS*COLS];</code>. But during compilation process (when dimension sizes <code>COLS</code> and <code>ROWS</code> must be constants by standard) the compiler also remembers the size of those dimensions, that are necessary to later address elements using syntax e.g. <code>array[x][y] = 45</code>. Compiler, being known of this size, will then replace <code>[x][y]</code> with the corresponding index to one-dimensional array using simple math: <code>[COLS*x + y]</code>.</p> <p>On the other hand, this is not the case with <strong>dynamically</strong> allocated arrays, if you want the same multi-dimensional functionality (in fact notation). As their size can be determined during runtime, they would have to remember the size of each additional dimension for later usage as well - and remember that for the whole life of the array. Moreover, system changes would have to be implemented here to work with arrays actually as multi-dimensional, leaving the form of <code>[x][y]</code> access notation in the code, not replacing it with an one-dimensional notation during compilation, but later replacing it within runtime.</p> <p>Therefore an <strong>absence</strong> of <em><code>array = new int[ROWS][COLS]</code></em> implies no necessity for <em><code>delete[][] array;</code></em>. And as already mentioned, it can't be used on your example to delete your "multi-dimensional" array, because your sub-arrays (additional dimensions) are allocated separately (using separate <code>new</code> call), so they are independent of the top array (<code>array_2D</code>) which contains them and they all can't be deleted at once.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload