Dynamic Memory


  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. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

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


  1. What is the output of this program?
    #include <iostream>
    #include <memory>
    #include <string>
    using namespace std;
    int main ()
    {
    string str[] = {"Interveiw", "Mania"};
    pair <string*, ptrdiff_t> Res = get_temporary_buffer<string>(2);
    if (Res.second>0)
    {
    uninitialized_copy ( str, str + Res.second, Res.first );
    for (int k = 0; k < Res.second; k++)
    cout << Res.first[k] << " ";
    return_temporary_buffer(Res.first);
    }
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    In this program, We are storing the string and retrieving the string by using get_temporary_method.



  1. What is the output of this program?
    #include <iostream>
    #include <memory>
    #include <string>
    using namespace std;
    int main ()
    {
    pair <string*, ptrdiff_t> Res = get_temporary_buffer<string>(5);
    if (Res.second > 0)
    {
    uninitialized_fill ( Res.first, Res.first + Res.second,
    "Bye " );
    for (int k = 0; k < Res.second; k++)
    cout << Res.first[k] ;
    return_temporary_buffer(Res.first);
    }
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In this program, We storing the string in the string buffer and then we are printing it.


  1. Which operator is used to deallocate the memory?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    free



  1. Which header file is used to manipulate the allocater?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Because all the memory allocation and deallocation libraries are declared in .