C++ Programming Questions and Answers – Large Objects

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) 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.

C++ Questions & Answers focuses on “Large Objects” along with answers, explanations and/or solutions:

Q 1. How to store the large objects in c++ if it extends its allocated memory?
A. queue
B. stack
C. memory heap
D. stack & queue

Show Answer Answer:-C. memory heap
Explanation Memory heap will store the large objects in c++ if it extends its allocated memory.

Q 2. When we are using heap operations what do we need to do to save the memory?
A. rename the objects
B. add the objects
C. both rename & delete the objects
D. delete the objects after processing

Show Answer Answer:-D. delete the objects after processing
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.

Q 3. Which container in c++ will take large objects?
A. string
B. class
C. vector
D. string & class

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

Q 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

Show Answer Answer:-C. X::X()
Explanation As we are passing the object without any attributes it will return as X::X(). Output: $ g++ large.cpp $ a.out X::X()

Q 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

Show Answer Answer:-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

Q 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

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

Q 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

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

Q 8. How to unlimit the size of the stack?
A. setrlimit()
B. unlimit()
C. both setrlimit() & unlimit()
D. setflimit()

Show Answer Answer:-A. setrlimit()
Explanation setrlimit() is used to unlimit the size of the stack.

Q 9. In Linux, how do the heaps and stacks are managed?
A. ram
B. secondary memory
C. static memory
D. virtual memory

Show Answer Answer:-D. virtual memory
Explanation In virtual memory, We can keep track of all the objects and access them much faster than any another.

Q 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

Show Answer Answer:-B. pass by reference
Explanation Because by using pass by reference we need to pass only address location, So it can save a lot of memory.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page