Home » C++ Programming » Questions and Answers » Question
  1. What is the output of this program?
    #include <iostream>
    #include <vector>
    using namespace std;
    int main ()
    {
    vector<int> VectorData;
    int * ptr;
    unsigned int k;
    ptr = VectorData.get_allocator().allocate(6);
    for (k = 0; k < 6; k++)
    VectorData.get_allocator().construct(&ptr[k], k);
    for (k = 0; k < 6; k++)
    cout << ' ' << ptr[k];
    for (k = 0; k < 6; k++)
    VectorData.get_allocator().destroy(&ptr[k]);
    VectorData.get_allocator().deallocate(ptr, 6);
    return 0;
    }
    1. 0 1
    2. 0 1 2
    3. 0 1 2 3
    4. 0 1 2 3 4
    5. 0 1 2 3 4 5
Correct Option: E

In this program, We allocated the values to the vector by using get allocater and then we are destroying it.



Your comments will be displayed only after manual approval.