Object Oriented Programming using C++ Questions and Answers – Delete Operator

This set of Object Oriented Programming (OOPs) using C++ Multiple Choice Questions & Answers (MCQs) focuses on “Delete Operator”.

1. What is a delete operator?
a) Deallocates a block of memory
b) Deallocates whole program memory
c) Deallocates only primitive data memory
d) Deallocates all the data reserved for a class
View Answer

Answer: a
Explanation: The delete operator is the reverse process of a new operator. It deallocates all the memory allocated for an object. The object can be of any type. The delete operator completely destroys an object so that the resources can be used for other purposes.

2. If an object is allocated using new operator ____________
a) It should be deleted using delete operator
b) It can’t be deleted using delete operator
c) It may or may not be deleted using delete operator
d) The delete operator is not applicable
View Answer

Answer: a
Explanation: The new operator allocates an object in memory and hence the memory allocation is bit different from usual allocation of an object. The delete operator can be used to delete the memory allocated for an object.

3. Does delete return any value?
a) Yes, positive value
b) Yes, negative value
c) Yes, zero value
d) No
View Answer

Answer: d
Explanation: The delete operator doesn’t return any value. Its function is to delete the memory allocated for an object. This is done in reverse way as that new operator works.
advertisement
advertisement

4. Which type of value has resulted from the delete operator?
a) void
b) void pointer
c) null pointer
d) null
View Answer

Answer: a
Explanation: The result of the delete operator is void. The values returned is of no use to the program or any other system function hence the return type is not defined for the delete operator.

5. If delete is used to delete an object which was not allocated using new _______________
a) Then out of memory error arises
b) Then unreachable code error arises
c) Then unpredictable errors may arise
d) Then undefined variable error arises
View Answer

Answer: c
Explanation: When the delete operator is used with the objects that were not allocated using new operator then unpredictable errors may arise. This is because the delete can’t perform the required actions on the type of memory allocated for the object.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Delete operator _________________
a) Can be used on pointers with null value
b) Can be used on pointers with void value
c) Can be used on pointer with value 0
d) Can be used on pointer with any value
View Answer

Answer: c
Explanation: The delete operator can be used on pointers with the value 0. This actually means that when new operator fails and return value 0 then deleting the result of failed new remains harmless. Hence the deletion is possible.

7. When delete operator is used ___________________ (If object has a destructor)
a) Object destructor is called after deallocation
b) Object destructor is called before deallocation
c) Object destructor is not used
d) Object destructor can be called anytime during destruction
View Answer

Answer: b
Explanation: The destructor is called before the memory is deallocated for any object. The destructor call initiates the destruction process and the deallocation of memory takes place.
advertisement

8. If delete is applied to an object whose l-value is modifiable, then _______________ after the object is deleted.
a) Its value is defined as null
b) Its value is defined as void
c) Its value is defined as 0
d) Its value is undefined
View Answer

Answer: d
Explanation: After performing delete operation on an object whole l-value is modifiable, its values becomes undefined. This is done so as to denote that the memory space is available to be used for other purposes.

9. How many variants of delete operator are available?
a) Only 1
b) Only 2
c) Only 3
d) Only 4
View Answer

Answer: b
Explanation: There are two variants of delete operator. One is for object deletion. Other is for deletion of object array.
advertisement

10. Which is the correct syntax to delete a single object?
a) delete *objectName;
b) objectName delete;
c) delete objectName;
d) objectName *delete;
View Answer

Answer: c
Explanation: The object to be deleted is mentioned after the keyword delete. This deletes the object from memory and free up the memory that was acquired by the object.

11. Which is the correct syntax to delete an array of objects?
a) delete [] objectName;
b) delete * objectName;
c) objectName[] delete;
d) delete objectName[];
View Answer

Answer: a
Explanation: The object array that has to be deleted is mentioned after the keyword delete. But after delete, empty square brackets have to be given to denote that the deletion have to be done on array of objects.

12. Which cases among the following produces the undefined result?
a) delete [] on an independent object
b) delete on an object array
c) delete [] on an object and delete on object array
d) Undefined result is never produced
View Answer

Answer: c
Explanation: The undefined result is always produced when we try to use delete [] with a single object. Because the type of deletion mismatches. Same in case where we try to apply delete to an object array.

13. The delete operator __________________
a) Invokes function operator delete
b) Invokes function defined by user to delete
c) Invokes function defined in global scope to delete object
d) Doesn’t invoke any function
View Answer

Answer: a
Explanation: The delete operator invokes the function operator delete. This function in turn performs all the delete operations on the mentioned object. This is ensures safe deletion.

14. For objects that are not of class type ______________
a) Global delete operator is invoked
b) Local delete operator is invoked
c) Global user defined function is invoked
d) Local function to delete object is called
View Answer

Answer: a
Explanation: The global delete operator is called to delete the objects that are not of class type. Class type includes class, union or struct. All objects of these types can be deleted using the global delete operator.

15. The delete operator __________________________
a) Can be defined for each class
b) Can’t be defined for each class
c) Can be defined globally only
d) Can’t be defined in a program explicitly
View Answer

Answer: a
Explanation: The delete operator can be defined for each class explicitly. If there is a class for which delete is not defined then the global delete operator is used. The definition of delete operator for each class is not necessary.

Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming (OOPs) using C++, 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.