Quantcast
Channel: User Zan Lynx - Stack Overflow
Viewing all articles
Browse latest Browse all 40

Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not?

$
0
0

I have seen it asserted several times now that the following code is not allowed by the C++ Standard:

int array[5];int *array_begin = &array[0];int *array_end = &array[5];

Is &array[5] legal C++ code in this context?

I would like an answer with a reference to the Standard if possible.

It would also be interesting to know if it meets the C standard. And if it isn't standard C++, why was the decision made to treat it differently from array + 5 or &array[4] + 1?


Viewing all articles
Browse latest Browse all 40

Trending Articles