Allocators Cpp MCQ

Errorlogger
0
1. Where does the allocaters are used?
a) Allocation of memory
b) Deallocation of memory
c) Used for pointers
d) Both a & b



2. Where does the allocaters are implemented?
a) Template library
b) Standard library
c) C++ code library
d) None of the mentioned



3. Which operator is used to allocate the memory?
a) =
b) +
c) new
d) free



4. What is the output of this program?
  1.     #include <iostream>
  2.     #include <memory>
  3.     #include <algorithm>
  4.     using namespace std;
  5.     int main ()
  6.     {
  7.         int numbers[] = {1, 5, 4, 5};
  8.         pair <int*, ptrdiff_t> result = get_temporary_buffer<int>(4);
  9.         if (result.second > 0)
  10.         {
  11.             uninitialized_copy (numbers, numbers + result.second, result.first);
  12.             sort (result.first, result.first + result.second);
  13.             for (int i = 0; i < result.second; i++)
  14.                 cout << result.first[i] << " ";
  15.             return_temporary_buffer (result.first);
  16.         }
  17.         return 0;
  18.     }
a) 1 5 5 4
b) 5 5 4 1
c) 1 4 5 5
d) 1 4 5 2



5. What is the output of this program?
  1.     #include <iostream>
  2.     #include <memory>
  3.     #include <string>
  4.     using namespace std;
  5.     int main ()
  6.     {
  7.         string numbers[] = {"steve", "jobs"};
  8.         pair <string*, ptrdiff_t> result = get_temporary_buffer<string>(2);
  9.         if (result.second>0) 
  10.         {
  11.             uninitialized_copy ( numbers, numbers + result.second, result.first );
  12.             for (int i = 0; i < result.second; i++)
  13.                 cout << result.first[i] << " ";
  14.             return_temporary_buffer(result.first);
  15.         }
  16.         return 0;
  17.     }
a) steve
b) jobs
c) jobs steve
d) steve jobs



6. What is the output of this program?
  1.     #include <iostream>
  2.     #include <memory>
  3.     #include <string>
  4.     using namespace std;
  5.     int main () 
  6.     {
  7.         pair <string*, ptrdiff_t>
  8.        result = get_temporary_buffer<string>(3);
  9.         if (result.second > 0)
  10.         {
  11.             uninitialized_fill ( result.first, result.first + result.second, 
  12.             "Hai" );
  13.             for (int i=0; i<result.second; i++)
  14.                 cout << result.first[i] ;
  15.             return_temporary_buffer(result.first);
  16.         }
  17.         return 0;
  18.     }
a) Hai
b) HaiHai
c) HaiHaiHai
d) None of the mentioned



7. Which operator is used to deallocate the memory?
a) destroy
b) free
c) empty
d) None of the mentioned



8. Which header file is used to manipulate the allocater?
a) allocater
b) memory
c) object
d) None of the mentioned



9. What is the use of reference member type in allocator?
a) Point to an element
b) Quantities of element
c) Reference to an element
d) None of the mentioned



10. What is the correct syntax for declaring an allocator?
a) template < class T > class allocator;
b) template < class T > class;
c) template class allocator;
d) None of the mentioned

Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !