Here is a listing of C++ Questions & Answers focuses on “Large Objects” along with answers, explanations and/or solutions:
1. How to store the large objects in c++ if it extends its allocated memory?
a) memory heap
d) stack & queue
Explanation: Memory heap will store the large objects in c++ if it extends its allocated memory.
2. When we are using heap operations what do we need to do to save the memory?
a) rename the objects
b) delete the objects after processing
c) both rename & delete the objects
d) add the objects
Explanation: When you allocate memory from the heap, you must remember to clean up objects when you’re done! Failure to do so is called a memory leak.
3. Which container in c++ will take large objects?
d) string & class
Explanation: Because the vector is mainly used to store large objects for the game programming and other operations etc.
4. What will be the output of the following C++ code?
using namespace std;
cout << "X::X()" << endl;
sample( sample const & )
cout << "X::X( X const & )" << endl;
sample& operator=( sample const & )
cout << "X::operator=(X const &)" << endl;
sample x = f();
a) X::operator=(X const &)
b) X::X( X const & )
Explanation: As we are passing the object without any attributes it will return as X::X().
$ g++ large.cpp $ a.out X::X()
5. How to stop your program from eating so much ram?
a) Find a way to work with the data one at a time
b) Declare it in program memory, instead of on the stack
c) Use the hard drive, instead of RAM
d) All of the mentioned
Explanation: Some of the ways to stop the program by consuming more ram. They are
i) Find a way to work with the data one at a time
ii) Declare it in program memory, instead of on the stack
iii) Use the hard drive, instead of RAM
6. Which option is best to eliminate the memory problem?
a) use smart pointers
b) use raw pointers
c) use virtual destructor
d) use smart pointers & virtual destructor
Explanation: Virtual destructor means is that the object is destructed in reverse order in which it was constructed and the smart pointer will delete the object from memory when the object goes out of scope.
7. What is the size of the heap?
d) Size of the heap memory is limited by the size of the RAM and the swap memory
Explanation: Size of the heap memory is limited by the size of the RAM and the swap memory.
8. How to unlimit the size of the stack?
c) both setrlimit() & unlimit()
Explanation: setrlimit() is used to unlimit the size of the stack.
9. In Linux, how do the heaps and stacks are managed?
b) secondary memory
c) virtual memory
d) static memory
Explanation: In virtual memory, We can keep track of all the objects and access them much faster than any another.
10. Which is used to pass the large objects in c++?
a) pass by value
b) pass by reference
c) both pass by value & reference
d) pass by name
Explanation: Because by using pass by reference we need to pass only address location, So it can save a lot of memory.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.