Created
April 11, 2010 18:30
-
-
Save zachelko/362958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
using namespace std; | |
int main() { | |
std::vector<int> foo; | |
// Add an item and then obtain an iterator to it | |
foo.push_back(3); | |
vector<int>::iterator iter = foo.begin(); | |
// Check the addresses of our iterator and the first item | |
std::cerr << "Address of the begin() iterator: " << &iter << std::endl; | |
std::cerr << "Address of our first object: " << &foo.at(0) << std::endl; | |
// Add a new item and check the address of our iterator, begin() | |
foo.push_back(4); | |
std::cerr << "Address of the begin() iterator after adding a new item: " << &iter << std::endl; | |
// Check the address of the first item, we expect it to be the same as our begin() iterator | |
std::cerr << "Address of our first object after adding a new item: " << &foo.at(0) << std::endl; | |
return 0; | |
} | |
// output | |
// | |
// Address of the begin() iterator: 0xbfbedb24 | |
// Address of our first object: 0x9c0d008 | |
// Address of the begin() iterator after adding a new item: 0xbfbedb24 | |
// Address of our first object after adding a new item: 0x9c0d018 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment