fork download
  1. #include <iostream>
  2.  
  3. #include <vector>
  4.  
  5. int main()
  6. {
  7. std::vector<int> arr = {1,2,3,4,5,6};
  8.  
  9. for(int i = 0; i < 6; ++i) {
  10. std::cout << "address of i-th element : " << &(*(arr.begin() + i)) << std::endl;
  11. }
  12.  
  13. // This might work, but DO NOT use it. UNDEFINED BEHAVIOR since end() cannot be dereferenced.
  14. std::cout << "address of end() element : " << &(*arr.end()) << std::endl;
  15. }
  16.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
address of i-th element : 0x9c42a10
address of i-th element : 0x9c42a14
address of i-th element : 0x9c42a18
address of i-th element : 0x9c42a1c
address of i-th element : 0x9c42a20
address of i-th element : 0x9c42a24
address of end() element : 0x9c42a28