You are on page 1of 8

 

Object Oriented Programming Questions and


Answers – Delete Operator
« Prev Next »

This set of Object Oriented Programming (OOPs) 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.

advertisement


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
di erent 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.

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 de ned 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 unde ned 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.

advertisement

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.

8. If delete is applied to an object whose l-value is modi able, then _______________ after the object is deleted.
a) Its value is de ned as null
b) Its value is de ned as void
c) Its value is de ned as 0
d) Its value is unde ned

View Answer

Answer: d
Explanation: After performing delete operation on an object whole l-value is modi able, its values becomes
unde ned. 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 unde ned result?
a) delete [] on an independent object
b) delete on an object array
c) delete [] on an object and delete on object array
d) Unde ned result is never produced

View Answer

Answer: c
Explanation: The unde ned 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 de ned by user to delete
c) Invokes function de ned 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.
advertisement

14. For objects that are not of class type ______________


a) Global delete operator is invoked
b) Local delete operator is invoked
c) Global user de ned 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 de ned for each class
b) Can’t be de ned for each class
c) Can be de ned globally only
d) Can’t be de ned in a program explicitly

View Answer

Answer: a
Explanation: The delete operator can be de ned for each class explicitly. If there is a class for which delete is
not de ned then the global delete operator is used. The de nition 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.
Participate in the Sanfoundry Certi cation contest to get free Certi cate of Merit. Join our social networks
below and stay updated with latest contests, videos, internships and jobs!

Telegram | Youtube | LinkedIn | Instagram | Facebook | Twitter | Pinterest

« Prev - Object Oriented Programming Questions and Answers – New Operator


» Next - Object Oriented Programming Questions and Answers – Automatic Variable

advertisement

Recommended Posts:
1. Ruby Programming Questions and Answers
2. C Programming Examples on Searching and Sorting
3. C Programming Examples on Bitwise Operations
4. Java Programming Examples on Exception Handling
5. Python Programming Examples on Stacks & Queues
6. Java Programming Examples on File Handling
7. C# Programming Examples on LINQ
8. C Programming Examples on Arrays
9. C# Programming Examples on Functions
10. Java Programming Examples
11. Java Programming Examples on Data-Structures
12. Java Programming Examples on String Handling
13. Java Programming Examples on Arrays
14. Java Programming Examples on Utility Classes
15. Java Programming Examples on Collections
16. C Programming Examples on Stacks & Queues
17. C# Programming Examples on Arrays 
18. Java Programming Examples on Classes
19. Java Programming Examples on Java.Lang
20. Object Oriented Programming Questions and Answers
advertisement

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and
CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about
competency developments in these areas. He lives in Bangalore and delivers focused
training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers,
Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies,
SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him
@ LinkedIn

Subscribe Sanfoundry Newsletter and Posts

Name*

Email*

Subscribe

About | Certi cations | Internships | Jobs | Privacy Policy | Terms | Copyright | Contact

     

© 2011-2020 Sanfoundry. All Rights Reserved.


You might also like