Dynamic Memory
- 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;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are sorting the array by using the allocator.
- 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;
}
-
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.
- 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;
}
-
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.
- Which operator is used to deallocate the memory?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
free
- Which header file is used to manipulate the allocater?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Because all the memory allocation and deallocation libraries are declared in .