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
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
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
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?
#include <iostream>
using namespace std;
class sample
{
public:
sample()
{
cout << "X::X()" << endl;
}
sample( sample const & )
{
cout << "X::X( X const & )" << endl;
}
sample& operator=( sample const & )
{
cout << "X::operator=(X const &)" << endl;
}
};
sample f()
{
sample tmp;
return tmp;
}
int main()
{
sample x = f();
return 0;
}
a) X::operator=(X const &)
b) X::X( X const & )
c) X::X()
d) X::operator
View Answer
Explanation: 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
View Answer
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
View Answer
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?
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
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
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
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
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]
- Check Computer Science Books
- Check Programming Books
- Check C++ Books
- Apply for Computer Science Internship
- Practice Computer Science MCQs