Questions and Answers


  1. How many items are there in sequence container?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    There are five items in sequence container. They are array, vector, list, forward_list and dequeue.


  1. Which is optional in the declaration of vector?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    The number of elements is optional. An empty vector means, A vector that contains zero elements.



  1. Pick out the correct statement about vector.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The syntax for declaring the vector element is vector<type> variable_name (number_of_elements);


  1. What is the output of this program?
    #include <iostream>
    #include <vector>
    using namespace std;
    int main ()
    {
    vector<int> VectorData (6);
    int* ptr = VectorData.data();
    *ptr = 30;
    ++ptr;
    *ptr = 15;
    ptr[2] = 150;
    for (unsigned k = 0; k < VectorData.size(); ++k)
    cout << ' ' << VectorData[k];
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, We are allocating the values to the vector and unallocated values are left as zero.



  1. What is the output of this program?
    #include <iostream>
    #include <vector>
    using namespace std;
    int main ()
    {
    vector<int> Data;
    Data.assign (5,50);
    vector<int>::iterator iter;
    iter=Data.begin()+1;
    int Array[] = {1200,20,40};
    cout << int (Data.size()) << '\n';
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, We are finding the size of the vector elements and resizing it.