CPP

CPP

Vector has 9 Questions
What do vectors represent?

Static arrays
Dynamic arrays
Stack
Queue
In which type of storage location are the vector members stored?

Contiguous storage locations
Non-contiguous storage locations
Both a & b
None of the mentioned
How many vector container properties are there in c++?

1
2
3
4
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         vector<int> a (3, 0);
  7.         vector<int> b (5, 0);
  8.         b = a;
  9.         a = vector<int>();
  10.         cout << "Size of a " << int(a.size()) << '\n';
  11.         cout << "Size of b " << int(b.size()) << '\n';
  12.         return 0;
  13.     }

Size of a 0 Size of b 3
Size of a 3 Size of b 5
Error
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         vector<int> first;
  7.         first.assign (7,100);
  8.         vector<int>::iterator it;
  9.         it=first.begin()+1;
  10.         int myints[] = {1776,7,4};
  11.         cout << int (first.size()) << '\n';
  12.         return 0;
  13.     }

10
9
8
7
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         unsigned int i;
  7.         vector<int> first;
  8.         vector<int> second (4, 100);
  9.         vector<int> third (second.begin(), second.end());
  10.         vector<int> fourth (third);
  11.         int myints[] = {16, 2, 77, 29};
  12.         vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
  13.         for (vector<int> :: iterator it = fifth.begin(); it != fifth.end(); ++it)
  14.             cout << ' ' << *it;
  15.         return 0;
  16.     }

16
16 2
16 2 77
16 2 77 29
Pick out the correct statement about vector.

vector values (5)
vector values (5)
vector (5)
None of the mentioned
Which is optional in the declaration of vector?

Type
Name
Vector
Number_of_elements
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         vector<int> myvector (5);
  7.         int* p = myvector.data();
  8.         *p = 10;
  9.         ++p;
  10.         *p = 20;
  11.         p[2] = 100;
  12.         for (unsigned i = 0; i < myvector.size(); ++i)
  13.             cout << ' ' << myvector[i];
  14.         return 0;
  15.     }

10 20 0 100 0
10 20 0 100
10 20 0
10 20