How to set a pointer to the the last element of a vector in C++

1 Answer

0 votes
#include <iostream>  
#include <vector> 

int main () {

    std::vector<int> vec{ 1, 3, 8, 23, 6, 99, 2, 100, 7 };
    int *end = &vec.back();
    
    std::cout << *end;
}
 
 
 
/*
run:
 
7
 
*/

 



answered Apr 23, 2024 by avibootz
...