Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>my understanding is that the == operator would just compare the addresses of the first two elements</p> </blockquote> <p>This is correct: if you compare two arrays using <code>==</code>, it will compare the addresses of the arrays, so it will only yield <code>true</code> if you compare an array with itself (or with a pointer to an element of the same type). See the description below for why.</p> <blockquote> <p>the = operator, when used like array1 = array2; would just cause array1 to point to the same memory location as array2 does.</p> </blockquote> <p>This is not correct because <strong>an array is not a pointer</strong>. <code>array1</code> can't point to the same memory location as <code>array2</code> because <code>array1</code> isn't a pointer, it's an array of elements.</p> <p>An array is a sequence of elements. In most contexts, the name of an array is implicitly converted to a pointer to its initial element. This is why you can do things like:</p> <pre><code>void f(int*); int data[10]; int* p = data; // this is the same as 'int* p = &amp;data[0];' f(data); // this is the same as 'f(&amp;data[0]);' </code></pre> <p><code>array1 = array2;</code> won't work because arrays are not assignable (mostly for historical reasons; I've never heard a convincing technical reason why it isn't allowed: it was never allowed in C, and C has been around for decades. There's some discussion of this in the comments and answers to <a href="https://stackoverflow.com/questions/3437110/why-does-c-support-memberwise-assignment-of-arrays-within-structs-but-not-gene">Why does C support memberwise assignment of arrays within structs but not generally?</a>).</p> <p>The following program will not compile:</p> <pre><code>int main() { int a[10], b[10]; a = b; } </code></pre> <p>For an "assignable" array, you can use the <code>array</code> container-like class found in Boost (<code>boost::array</code>), C++ TR1 (<code>std::tr1::array</code>), or C++0x (<code>std::array</code>). It is actually a class that contains an array; it can be copied and it provides many of the benefits of the Standard Library containers plus the performance characteristics of an array and the ability to use its data as an array when you need to.</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