Suppose, I have declared a vector in C++ like this:
vector<int>numbers = {4,5,3,2,5,42};
I can iterate it through the following code:
for (vector<int>::iterator it = numbers.begin(); it!=numbers.end(); it++){
// code goes here
}
I'd now want to discuss programming in the for loop block.
I can use this iterator to access and modify any value.
Let's imagine that I want to tenfold the print and every value.
The code would then be:
*it+=10;
cout << *it << endl;
I have the ability to output the addresses of both the iterator and the elements being iterated.
You may output the iterator's address by using:
cout << &it << endl;
Address of iterated elements can be printed by:
cout << &(*it) << endl;
But why the iterator itself could not printed by doing the following?
cout << it <<endl;
I initially believed the convention was a JAVA invention due to its security-related nature.
If it is, though, how come I was able to print its address?
But is there another way to accomplish this?
Why not, then?