Test Series - cpp

Test Number 36/102

Q: What is a friend function in C++?
A. A function which can access all the private, protected and public members of a class
B. A function which is not allowed to access any member of any class
C. A function which is allowed to access public and protected members of a class
D. A function which is allowed to access only public members of a class
Solution: Friend function in C++ is a function which can access all the private, protected and public members of a class.
Q: Pick the correct statement.
A. Friend functions are in the scope of a class
B. Friend functions can be called using class objects
C. Friend functions can be invoked as a normal function
D. Friend functions can access only protected members not the private members
Solution: Friend functions are not in the scope of a class and hence cannot be called through a class object. A friend function can access all types of members of the class. They can be invoked as a normal function.
Q: Which of the following is correct about friend functions?
A. Friend functions use the dot operator to access members of a class using class objects
B. Friend functions can be private or public
C. Friend cannot access the members of the class directly
D. All of the mentioned
Solution: Friend function can be declared either in private or public part of the class. A friend function cannot access the members of the class directly. They use the dot membership operator with a member name.
Q: Which keyword is used to represent a friend function?
A. friend
B. Friend
C. friend_func
D. Friend_func
Solution: friend keyword is used to declare a friend function.
Q: How to store the large objects in c++ if it extends its allocated memory?
A. memory heap
B. stack
C. queue
D. stack & queue
Solution: Memory heap will store the large objects in c++ if it extends its allocated memory.
Q: 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
Solution: 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: Which container in c++ will take large objects?
A. string
B. class
C. vector
D. string & class
Solution: Because the vector is mainly used to store large objects for the game programming and other operations etc.
Q: 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
Solution: 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: 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
Solution: 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: 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
Solution: Size of the heap memory is limited by the size of the RAM and the swap memory.

You Have Score    /10