This set of Object Oriented Programming (OOPs) Multiple Choice Questions & Answers (MCQs) focuses on “Delete Operator”.
1. What is 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
Explanation: The delete operator is reverse process of 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
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
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.
4. Which type of value is resulted from the delete operator?
b) void pointer
c) null pointer
Explanation: The result of 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
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.
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
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
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.
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
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
Explanation: There are two variants of delete operator. One is for object deletion. Other is for deletion of object array.
10. Which is the correct syntax to delete a single object?
a) delete *objectName;
b) objectName delete;
c) delete objectName;
d) objectName *delete;
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 array of objects?
a) delete  objectName;
b) delete * objectName;
c) objectName delete;
d) delete objectName;
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
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
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
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
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), here is complete set of 1000+ Multiple Choice Questions and Answers.