C++ Programming using vector data structure example sample question with solution
1.What
will be the output of this code?
vector<int>
v(5);
for
(int k=0; k<v.size( ); k++)
v[k]=k+1;
vector<int>
copy;
copy=v;
v[4]=44;
copy.push_back(6);
for
(int k=0; k<copy.size( ); k++)
cout<< copy[k]<<" ";
|
2.
What will be the output of this code?
vector<int>
v(5);
for
(int k=0; k<v.size( ); k++)
v[k]=k+1;
for
(int k=0; k<v.size( )/2; k++) {
int temp = v[k];
v[k] = v[v.size( )-k-1];
v[v.size( )-k-1] = temp;
}
for
(int k=0; k<v.size( ); k++)
cout<< v[k]<<" ";
|
0 comments:
Post a Comment