I have a pointer to a vector. Now, how can I read the contents of the vector through pointer?
I have a pointer to a vector. Now, how can I read the contents of the vector through pointer?
vector <int> numbers {10,20,30,40};
vector <int> *ptr {nullptr};
ptr = &numbers;
for(auto num: *ptr){
cout << num << endl;
}
cout << (*ptr).at(2) << endl; // 20
cout << "-------" << endl;
cout << ptr -> at(2) << endl; // 20