How to update a vector in method
- by gurpinars
I'm new to C++ and trying to understand vectors. My goal is to update a vector in method:
#include <vector>
#include <iostream>
using namespace std;
void test(vector<int>& array){
for(int i=0;i<10;i++){
array.push_back(i);
}
}
int main(){
// some integer value
vector<int> array(10);
test(array);
for(int i=0;i<array.size();++i)
cout<<array.at(i)<<endl;
cout<<"array size:"<<array.size()<<endl;
return 0;
}
output:
0
0
0
0
0
0
0
0
0
0
0
1
2
3
4
5
6
7
8
9
array size:20
I haven't figure out why 10 zeros add vector at first?