Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which among the following is true?(a) New operator can’t allocate functions but pointer to functions can be allocated(b) New operator can allocate functions as well as pointer to functions(c) New operator can allocate any type of functions(d) New operator is not applicable with functions allocationI got this question during an interview.My question comes from New Operator in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct option is (a) NEW OPERATOR can’t allocate functions but pointer to functions can be allocated

Explanation: The new operator can’t allocate functions but can allocate pointer to the functions. This is a security feature as WELL as to REDUCE the ambiguity in CODE. The new keyword is not given functionality to directly allocate any function.

52.

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 dataI had been asked this question during an interview for a job.My question is from New Operator topic in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right answer is (B) Doesn’t allocate reference TYPES

To explain I would say: 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.

53.

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 enumerationsThis question was addressed to me in class test.I need to ask this question from New Operator in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right OPTION is (d) Type name can’t contain CONST, volatile, class declaration or enumerations

To explain: 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.

54.

Which among the following is correct syntax to declare a 2D array using new operator?(a) char (*pchar)[10] = new char[][10];(b) char (pchar) = new char[][10];(c) char (*char) = new char[10][];(d) char (*char)[][10]= new char;The question was posed to me by my college professor while I was bunking the class.I would like to ask this question from New Operator topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct OPTION is (a) CHAR (*pchar)[10] = new char[][10];

The explanation is: The new operator usage to declare a 2D array requires a pointer and size of array to be declared. Data type and then the pointer with size of array. The left index can be left BLANK or any VARIABLE can be ASSIGNED to it.

55.

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 codeI had been asked this question by my school teacher while I was bunking the class.Asked question is from New Operator in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct choice is (b) After the allocation of memory

Explanation: 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.

56.

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_handlerI have been asked this question in an internship interview.This key question is from New Operator topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct option is (d) _set_new_handler

Explanation: 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.

57.

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 programI had been asked this question in my homework.The doubt is from New Operator topic in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct option is (c) Either THROWS an exception or returns ZERO

For explanation: 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.

58.

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 entriesThe question was posed to me by my school teacher while I was bunking the class.Enquiry is from New Operator in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct choice is (c) Add new VTABLE slot entries

The BEST I can explain: 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.

59.

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 programThe question was asked in a national level competition.My question comes from New Operator in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct option is (b) Allocates memory for an object or ARRAY and returns a particular POINTER

For explanation: 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.