A question about pointer

1
2
3
int nums[100];

int *en = nums+100;


I am reading a book. The book says that 'int *en == nums+100;' defines en as a pointer to the last element of the array nums.

Can you revise the statement like this 'int *en = nums+99;' instead of 'nums+100;'?

I think it makes sense to me that 'en' indicates nums[0+99], which is the last element.
The book says that 'int *en == nums+100; defines en as a pointer to the last element of the array nums.

That's not right, it points to the element after the last. You sure that's exactly what the book says?

I think it makes sense to me that 'en' indicates nums[0+99], which is the last element

Correct.
I just copied the definition literally from the book, "Accelerated c++".

Anyway, it's good to know that my statement is right.
My copy of the book says

int* en = nums + 100;
Defines en as a pointer to (one past) the last element of the array nums


If you made it this far, you should already know what off-the-end iterators are.
Last edited on
Topic archived. No new replies allowed.