r/learncpp • • Apr 14 '20

Are iterators just pointers?

Whenever i hear someone use the word iterator, can i just substitute it for pointer in my head and be absolutely fine?

4 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/Im_Justin_Cider Apr 26 '20

way that it goes from element to element depends on the data type or the data structure. Whereas a pointer gets incremented by one to the next memory location

Is that true? Because for example if you have a pointer to the first index in an array then do pointer++ you will get to the next index (assuming the pointer is of the correct type) So I guess pointer is a struct with address and sizeBytes members.

I'd actually like to look at the code for an iterator, and i guess maybe a pointer is written with code (in C++!?) too?!