Note that there are some explanatory texts on larger screens.

plurals
  1. POEquality & assignment operators used on arrays in C++
    primarykey
    data
    text
    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. COIt's interesting to think that == works for an array while it doesn't for an std::vector!
      singulars
    2. CO@junjanes: `==` does indeed work for `std::vector`. For arrays `==` tests for identity equality (are the left and right hand sides the same array), since `==` for arrays really compares the addresses of the initial elements of the arrays. This is not usually what you want when you want to test whether arrays are "equal." For `vector`, the `==` does what you would expect for an equality comparison: it tests whether all of the elements in one `vector` compares equal to the corresponding elements in the other `vector`.
      singulars
    3. COIt's actually quite hard to explain why arrays aren't assignable. "Because the standard says so", obviously, but they easily could have been. The reason for the decision is quite old, and AFAIK is something like: during the initial design of C there was a serious possibility of making array names actually *be* pointers, initialized pointing to automatic storage. It would then be potentially confusing whether assignment should copy the array or reseat the pointer, so rather than do either it was ruled out, and the decision to rule it out stuck. Is this C++ homework, or history homework? ;-)
      singulars
 

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