Test Series - oops

Test Number 72/78

Q: Microsoft C++ Components extensions support new keyword to _____________
A. Modify a vtable
B. Replace a vtable slot entry
C. Add new vtable slot entries
D. Rearrange vtable slot entries
Solution: The new keyword is used for adding new vtable slot entries. This is an additional feature in Microsoft C++. It can use predefined class object for this work.
Q: Initializers __________________
A. Are used for specifying arrays
B. Are used to defined multidimensional arrays
C. Can’t be specified for arrays
D. Can’t be specified for any data
Solution: The initializers can’t be specified for arrays. The initializers can create arrays of object if and only if the class has a default constructor. That is a zero argument constructor so that it can be called without any argument.
Q: 
A. 
B. 
C. 
D. 
Solution: 
Q: The new operator _____________
A. Can allocate reference types too
B. Doesn’t allocate reference types
C. Can allocate reference to objects
D. Doesn’t allocate any data
Solution: The new operator doesn’t allocate reference types. This is because the reference types are not objects. The new operator is used to allocate memory to the direct objects.
Q: What is the new operator?
A. Allocates memory for an object or array
B. Allocates memory for an object or array and returns a particular pointer
C. Used as return type when an object is created
D. Used to declare any new thing in a program
Solution: The new keyword is used to allocate memory of an object or array. The new object or array can be of any type. Then it returns a suitable non zero pointer to the object.
Q: If new throws an error, which function can be called to write a custom exception handler?
A. _set_handler
B. _new_handler
C. _handler_setter
D. _set_new_handler
Solution: If the default exception handler has to be replaced by a user defined handler, we can call _set_new_handler run-time library function with the function name as an argument. This lets the programmer to give a custom definition for handling new operator failure.
Q: In C++, if new operator is used, when is the constructor called?
A. Before the allocation of memory
B. After the allocation of memory
C. Constructor is called to allocate memory
D. Depends on code
Solution: The constructor function is called after the allocation of memory. In C++ the feature works in a bit different way. The memory for all the data members is allocated first and then the constructor function is called to finalize the memory allocated.
Q: For declaring data by using new operator ________________
A. Type name can’t contain const
B. Type name can’t contain volatile
C. Type name can’t contain class declarations
D. Type name can’t contain const, volatile, class declaration or enumerations
Solution: The declaration of any data where we use new operator, any of the mentioned types are not allowed. This is because the new operator allocated memory based on the type of data which can be allocated dynamically.
Q: Which among the following is added in grammar of new operator?
A. Finalize
B. Arg
C. Initializer
D. Allocator
Solution: The new operator grammar is added with an initializer field. This can be used to initialize an object with a user defined constructor. Hence can allocate memory as intended by the programmer.
Q: What happens when new fails?
A. Returns zero always
B. Throws an exception always
C. Either throws an exception or returns zero
D. Terminates the program
Solution: While creating new objects, the new operator may fail because of memory errors or due to permissions. At that moment the new operator returns zero or it may throw an exception. The exception can be handled as usual.
Q: The new operator _________________
A. Invokes function operator new
B. Doesn’t invoke function operator new
C. Invokes function operator only if required
D. Can’t invoke function operator new implicitly
Solution: The new operator invokes function operator new. This is done to allocate the storage to an object. ::operator new is called for storage allocation implicitly.

You Have Score    /11