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 (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. 30 15 0 150 0 0
    2. 30 15 0 150 0
    3. 30 15 0 150
    4. 30 15 0
    5. 30 15
Correct Option: A

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



Your comments will be displayed only after manual approval.