Vector

1

Which is optional in the declaration of vector?

A. Type
B. Name
C. Vector
D. Number_of_elements

2

 Pick out the correct statement about vector.
a) vector<int> values (5)
b) vector values (5)
c) vector<int> (5)
d) None of the mentioned


3

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    int main ()
5.
    {
6.
        vector 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.
    }
A. 10 20 0 100 0
B. 10 20 0 100
C. 10 20 0
D. 10 20

4

What is the output of this program?

 
1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    int main ()
5.
    {
6.
        vector first;
7.
        first.assign (7,100);
8.
        vector::iterator it;
9.
        it=first.begin()+1;
10.
        int myints[] = {1776,7,4};
11.
        cout << int (first.size()) << '\n';
12.
        return 0;
13.
    }
A. 10
B. 9
C. 8
D. 7

5

What is the output of this program?

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

a) Size of a 0

Size of b 3

b) Size of a 3

Size of b 5

c) Error

d) None of the mentioned