Tuesday, May 1, 2012

8.23

In C++ the equality test == can be applied to arrays, but it tests the wrong thing. Also, the assignment operator = cannot be applied to arrays at all. Explain


The name of an array references the memory address of the first element of the array, so using == does not test if the arrays themselves are equal, but rather whether they exist at the same memory location. The assignment operator =, when applied to an array, would result in two arrays existing in the same location, and so the compiler prevents this.

No comments:

Post a Comment