250+ TOP MCQs on Large Objects and Answers

This section on C++ quiz on “Large Objects”. One shall practice these quizzes to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ quiz comes with the detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ quiz 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
b) stack
c) queue
d) stack & queue
Answer: a
Clarification: 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
Answer: b
Clarification: 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?
a) string
b) class
c) vector
d) string & class
Answer: c
Clarification: 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?

  1.     #include 
  2.     using namespace std;
  3.     class sample
  4.     {
  5.         public:
  6.         sample() 
  7.         {  
  8.             cout << "X::X()" << endl; 
  9.         }
  10.         sample( sample const & ) 
  11.         {  
  12.             cout << "X::X( X const & )" << endl;
  13.         }
  14.         sample& operator=( sample const & )
  15.         { 
  16.             cout << "X::operator=(X const &)" << endl;
  17.         }
  18.     };
  19.     sample f() 
  20.     {
  21.         sample tmp;
  22.         return tmp;
  23.     }
  24.     int main() 
  25.     {
  26.         sample x = f();
  27.         return 0;
  28.     }

a) X::operator=(X const &)
b) X::X( X const & )
c) X::X()
d) X::operator
Answer: c
Clarification: As we are passing the object without any attributes it will return as X::X().
Output:

$ 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
Answer: d
Clarification: 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
Answer: d
Clarification: 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?
a) 10MB
b) 500MB
c) 1GB
d) Size of the heap memory is limited by the size of the RAM and the swap memory
Answer: d
Clarification: 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?
a) setrlimit()
b) unlimit()
c) both setrlimit() & unlimit()
d) setflimit()
Answer: a
Clarification: setrlimit() is used to unlimit the size of the stack.

9. In Linux, how do the heaps and stacks are managed?
a) ram
b) secondary memory
c) virtual memory
d) static memory
Answer: c
Clarification: 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
Answer: b
Clarification: Because by using pass by reference we need to pass only address location, So it can save a lot of memory.

Global Education & Learning Series – C++ Programming Language.