Why point to a memory cell for the last element in an array or vector?

Suppose we have an array named datasize 5. If we pass this array as an argument to a function std::end, for example

int *ptr = std::end(data);

It will return a pointer pointing to the memory location for the last element in the array.

Question

What is the point of pointing to a pointer to a memory cell for the last element in an array? Why not just point to the last element of the array?

+6
source share
1 answer

To specify an "empty" container / sequence of one with elements in it.

, , , "".

A NULL , , NULL . . , " " ( pre ++ 98 )?

/ , , operator <, . ( ), == !=, ( ); " " .

"" ; STL. ++.

, , STL.

; , , , , , , /.

.

+7

Source: https://habr.com/ru/post/1014718/


All Articles