Home » C++ Programming » Dynamic Memory » Question
  1. What is the output of this program?
    #include <iostream>
    #include <memory>
    #include <algorithm>
    using namespace std;
    int main ()
    {
    int num[] = {11, 15, 14, 15, 14, 11};
    pair <int*, ptrdiff_t> Res = get_temporary_buffer<int>(6);
    if (Res.second > 0)
    {
    uninitialized_copy (num, num + Res.second, Res.first);
    sort (Res.first, Res.first + Res.second);
    for (int k = 0; k < Res.second; k++)
    cout << Res.first[k] << " ";
    return_temporary_buffer (Res.first);
    }
    return 0;
    }
    1. 11 11
    2. 11 11 14
    3. 11 11 14 14 15 15
    4. 14 15 15
    5. 14 15
Correct Option: C

In this program, We are sorting the array by using the allocator.



Your comments will be displayed only after manual approval.