Test Series - oops

Test Number 73/78

Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: Does delete return any value?
A. Yes, positive value
B. Yes, negative value
C. Yes, zero value
D. No
Solution: 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.
Q: Which type of value has resulted from the delete operator?
A. void
B. void pointer
C. null pointer
D. null
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.
Q: How many variants of delete operator are available?
A. Only 1
B. Only 2
C. Only 3
D. Only 4
Solution: There are two variants of delete operator. One is for object deletion. Other is for deletion of object array.
Q: Which is the correct syntax to delete a single object?
A. delete *objectName;
B. objectName delete;
C. delete objectName;
D. objectName *delete;
Solution: 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.
Q: Which is the correct syntax to delete an array of objects?
A. delete [] objectName;
B. delete * objectName;
C. objectName[] delete;
D. delete objectName[];
Solution: 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.
Q: 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
Solution: 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.

You Have Score    /10