728x90 AdSpace

Latest Article



Using vector in C++ Example sample Question with solution





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]<<"  ";

1 2 3 4 5 6

 


         




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]<<"  ";

5 4 3 2 1
 






no image
  • Title : Using vector in C++ Example sample Question with solution
  • Posted by :
  • Date : 13:05
  • Labels :






  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment