Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's take that bit by bit.</p> <p><code>data</code> is the iterator showing where to start. It's an array, but in C and C++ arrays decay to pointers on any provocation, so it's used as a pointer. Start taking in data from <code>data</code> on, and continue until the end iterator.</p> <p>The end iterator is a certain amount past the start iterator, so it can be expressed as <code>data + &lt;something&gt;</code>, where <code>&lt;something&gt;</code> is the length. The start iterator is an <code>int []</code> that is treated as an <code>int *</code>, so we want to find the length in <code>int</code>s. (In C and C++, pointers increment by the length of the pointed-to type.)</p> <p>Therefore, <code>sizeof(data) / sizeof(int)</code> should be the length of the array. <code>sizeof(data)</code> is the total size of the array in bytes. (This is one of the differences between arrays and pointers: arrays have a defined size, while pointers point to what might be the start of an array of unknown size.) <code>sizeof(int)</code> is the total size of an int in bytes, and so the quotient is the total size of <code>array</code> in <code>int</code>s.</p> <p>We want the size of <code>array</code> in <code>int</code>s because <code>array</code> decays into an <code>int *</code>, and so <code>data + x</code> points to the memory location x <code>int</code>s past <code>data</code>. From a beginning and a total size, we find the end of <code>data</code>, and so we copy everything in <code>data</code> from the beginning to the end.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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