Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This code will <em>not</em> work in either C or C++. An array of type <code>int[4][4]</code> is not convertible to a pointer of type <code>int **</code> (which is what <code>int *arr[]</code> stands for in parameter declaration). If you managed to <em>compile</em> it in C, it is simply because you probably ignored a C compiler warning of basically the same format as the error message you got from C++ compiler. (Sometimes C compilers issue <em>warnings</em> for what is essentially an <em>error</em>.)</p> <p>So, again, don't make assertions that are not true. This code does not work in C. In order to convert a built-in 2D array into a <code>int **</code> pointer you can use a technique like this one</p> <p><a href="https://stackoverflow.com/questions/1584100/converting-multidimensional-arrays-to-pointers-in-c">Converting multidimensional arrays to pointers in c++</a></p> <p>(See the accepted answer. The problem is exactly the same.)</p> <p><strong>EDIT:</strong> The code <em>appears</em> to work in C because another bug in the printing code is masquerading the effects of the bug in array passing. In order to properly access an element of an <code>int **</code> pseudo-array, you have to use expression <code>*(*(arr + i) + j)</code>, or better a plain <code>arr[i][j]</code> (which is the same thing). You missed the extra <code>*</code> which made it print something that has absolutely nothing to do with the content of your array. Again, initialize your array in <code>main</code> to something else to see that the results you are printing in C have absolutely nothing to do with the your intended content of the array.</p> <p>If you change the <code>printf</code> statement as shown above, your code will most likely crash because of the array-passing bug I described initially.</p> <p>One more time: you cannot pass a <code>int[4][4]</code> array as an <code>int **</code> pseudo-array. This is what the C++ is telling you in the error message. And, I'm sure, this is what your C compiler told you, but you probably ignored it, since it was "just a warning".</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.
    3. VO
      singulars
      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