C++ Programming Questions and Answers – Large Objects

This section on C++ Multiple Choice Questions focuses on “Large Objects”. One shall practice these questions 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++ questions comes with the detailed explanation of the answers which helps in better understanding of C++ concepts.

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
b) stack
c) queue
d) stack & queue
View Answer

Answer: a
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
View Answer

Answer: b
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?
a) string
b) class
c) vector
d) string & class
View Answer

Answer: c
Explanation: Because the vector is mainly used to store large objects for the game programming and other operations etc.
advertisement
advertisement

4. What will be the output of the following C++ code?

  1.     #include <iostream>
  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
View Answer

Answer: c
Explanation: As we are passing the object without any attributes it will return as X::X().
Output:

Note: Join free Sanfoundry classes at Telegram or Youtube
$ 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
View Answer

Answer: d
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
advertisement

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
View Answer

Answer: d
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.
advertisement

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
View Answer

Answer: d
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?
a) setrlimit()
b) unlimit()
c) both setrlimit() & unlimit()
d) setflimit()
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
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
View Answer

Answer: b
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.