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.

1.

Why are functions extern by default?(a) Because functions are always private(b) Because those are not visible throughout the program(c) Because those can’t be accessed in all parts of the program(d) Because those are visible throughout the programThis question was addressed to me in an international level competition.This intriguing question originated from Extern Variable in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct choice is (a) Because functions are always private

To explain I would say: The program have all of its functions VISIBLE throughout the program usually. Also, there is no specific VALUE that a function must contain. HENCE the functions are extern by DEFAULT.

2.

If extern variable is initialized with the declaration then _______________________(a) Also the header file with definition is required(b) The header file with definition must be included(c) There is no need to include any other header file for definition(d) The extern variable produces compile time errorThis question was addressed to me during an interview.This question is from Extern Variable in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct CHOICE is (c) There is no need to include any other HEADER FILE for definition

Explanation: When the value for the extern VARIABLE is defined with its declaration, then there is no need to include any file for the definition of the variable. The Initialization ACTS as a definition for the extern variable in the file itself.

3.

If the definition is given in the header file that we include then ________________(a) The program can run successfully(b) Also the program should define the extern variable(c) The extern variable must contain two definitions(d) Extern variable can’t be used in the programThe question was asked by my school teacher while I was bunking the class.This question is from Extern Variable topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct option is (a) The program can run successfully

To EXPLAIN I WOULD say: The program runs successfully. This is because only one DEFINITION of any variable is allowed. And hence the definition from the source file that is INCLUDED will be used.

4.

Which is the correct syntax for extern function declaration?(a) extern function_name(argument_list);(b) extern return_type function_name(argument_list);(c) extern (return_type)function_name(argument_list);(d) return_type extern function_name(argument_list);This question was posed to me in unit test.My question is based upon Extern Variable topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct choice is (b) extern return_type function_name(argument_list);

Easiest explanation - The syntax must CONTAIN the keyword extern first, to DENOTE that the function is extern. Though the function are extern by default but among the given choices, it should contain the keyword, for explicit DECLARATION. Then the usual function declaration FOLLOWS.

5.

Which is the correct syntax for extern variable declaration?(a) extern data_type variable_name;(b) extern variable_name;(c) data_type variable_name extern;(d) extern (data_type)variable_name;I have been asked this question in unit test.Question is taken from Extern Variable topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct answer is (a) extern data_type variable_name;

To EXPLAIN: The syntax firstly contains the KEYWORD extern. Then the data type of the VARIABLE is GIVEN. Then the variabel name is MENTIONED by which it will be used in the program.

6.

Which of the following results in the allocation of memory for the extern variables?(a) Declaration(b) Definition(c) Including file(d) Memory is not allocated for extern variablesI have been asked this question in my homework.Asked question is from Extern Variable in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct ANSWER is (b) Definition

For EXPLANATION: The memory for the extern VARIABLES are allocated DUE to their definition. When the variables are declared, it only indicates the compiler that the variable is going to be used somewhere. But definition makes the compiler to ALLOCATE the memory for the variables.

7.

Even if a variable is not declared as extern, it is extern by default.(a) True(b) FalseI got this question by my school principal while I was bunking the class.This question is from Extern Variable in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct option is (b) FALSE

Best explanation: The STATEMENT is false. The variables are not EXTERN by default. If those are made extern by default, then the memory will never be ALLOCATED for those extern variables. HENCE we make the variables extern explicitly.

8.

Whenever a function is declared in a program _____________________(a) extern can be used only in some special cases(b) extern can’t be used(c) function is extern by default(d) it can’t be made externI got this question in examination.This intriguing question comes from Extern Variable in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right answer is (C) function is extern by DEFAULT

Best explanation: Even if we don’t specify a function to be extern, by default all the functions are exter. The COMPILER adds the keyword at the beginning of the function declaration. If there is an extern function to be USED then it will be used otherwise the new function only will be used.

9.

Which condition is true if the extern variable is used in a file?(a) All the header files declare it(b) Only few required files declare it(c) All header files declared it if required(d) Only one header file should declare itThis question was addressed to me in semester exam.My doubt is from Extern Variable topic in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The CORRECT choice is (d) Only one header file should declare it

To EXPLAIN: Only one header file should declare the EXTERN variable to be USED. There must not be more than one file declaring the same extern variable. This is to ENSURE that there is no ambiguity in using the extern variable.

10.

What does a header file contain for an extern variable?(a) Only declaration of variables(b) Only definition of variables(c) Both declaration and definition of variables(d) Neither declaration nor definitionThis question was posed to me in examination.Enquiry is from Extern Variable in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right option is (a) Only declaration of variables

The best explanation: The HEADER file only CONTAINS the declaration of variables that are extern. It doesn’t contain any static VARIABLE definitions.

11.

To use extern variable _____________________(a) The source file must not be included in the new file code(b) The source file itself must be used for a new program(c) The source file must be included in the new file(d) The source file doesn’t matter for extern variablesI had been asked this question in an interview for internship.This is a very interesting question from Extern Variable topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct choice is (c) The source file must be INCLUDED in the new file

Explanation: The source file must be included in the file which NEEDS to use the EXTERN variable. This is done to ENSURE that the variables that are already declared can be used again. Only the declarations are used from one file to ANOTHER.

12.

Which among the following is true for the variables?(a) Variable can be defined only once(b) Variable can be defined any number of times(c) Variable must be defined more than one time(d) Variable can be defined in different filesI had been asked this question during an interview for a job.I need to ask this question from Extern Variable in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct answer is (a) Variable can be defined only once

The best explanation: The variables can be defined only once. Once the variable is defined, then it can’t be DECLARED again. The DEFINITION of a variable is ACTUAL allocation of MEMORY for the variable.

13.

Which among the following is a correct statement for variables?(a) Variable can be declared many times(b) Variable can be declared only one time(c) Variable declaration can’t be done more than ones(d) Variable declaration is always done more than one timeThis question was addressed to me in my homework.My question is taken from Extern Variable in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right CHOICE is (a) Variable can be DECLARED MANY times

For explanation: The variables can be declared any number of times. There is no RESTRICTION on how many times a single variables can be declared. Declaration is just an indication that the variable will be used in the PROGRAM.

14.

What is extern variable?(a) Variables to be used that are declared in another object file(b) Variables to be used that are declared in another source file(c) Variables to be used that are declared in another executable file(d) Variables to be used that are declared in another programThis question was addressed to me in my homework.My doubt is from Extern Variable in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct choice is (B) VARIABLES to be used that are declared in another source file

Best EXPLANATION: The variables that are declared in another source file can be accessed in other FILES using extern variables. The extern variables must be mentioned explicitly. The source file is included to use its variables.

15.

How are automatic variables different from the instance variables?(a) Automatic variables are initialized automatically but instances are not(b) Automatic variables are given zero values initially and not instances(c) Instance variables have to be initialized explicitly and automatic implicitly(d) Instance variables are initialized implicitly while automatic are notThe question was posed to me in my homework.This intriguing question originated from Automatic Variable in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct choice is (d) Instance variables are initialized IMPLICITLY while AUTOMATIC are not

Explanation: The automatic variables have to be initialized EXPLICITLY. But in case of instances, those are initialized automatically during execution of the PROGRAM. The conventions are mandatory.

16.

In Perl, using which operator are the local variables created?(a) Dot(b) Arrow(c) Scope resolution(d) myThe question was posed to me at a job interview.My question is from Automatic Variable topic in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct option is (d) my

Easy explanation - The LANGUAGE perl supports local variables but the concept is BIT different. And if the values are not ASSIGNED to the local variables then it CONTAINS undef VALUE.

17.

Which error is produced if the automatic variables are used without declaration?(a) Undefined symbol(b) Memory error(c) Type mismatch(d) Statement missingI got this question in my homework.This intriguing question comes from Automatic Variable topic in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The CORRECT option is (a) Undefined symbol

The explanation is: If the automatic variables are used without DECLARATION or are used before the declaration then the compiler THROWS an error. The error that the symbol is undefined. The compiler MUST know everything before that can be used.

18.

The automatic variables _________________________(a) Must be declared after its use(b) Must be declared before using(c) Must be declared, can be anytime(d) Must not be initializedI have been asked this question at a job interview.This key question is from Automatic Variable topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer» RIGHT OPTION is (b) Must be declared before using

For explanation: All the automatic VARIABLES in a program must be declared before their use. The COMPILER won’t allow any use of variable if those are not declared before their use.
19.

Does java contain auto or register keywords?(a) Yes, for declaring every type of variable(b) Yes, only to declare cache registers(c) No, because java doesn’t support automatic variables(d) No, java supports local variable conceptI have been asked this question in homework.My query is from Automatic Variable in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct choice is (d) No, java supports local VARIABLE concept

Explanation: The AUTO and register keywords are not SUPPORTED in java. Though the same is ALLOWED in java without specifying any of those keywords. The variables are local variables. But java makes it mandatory to INITIALIZE all of the local variables in a program.

20.

Constructor of automatic variables is called ____________________(a) When execution reaches the place of declaration of automatic variables(b) When the program is compiled(c) When the execution is just started(d) Just before the execution of the programThis question was addressed to me in an interview for job.I'd like to ask this question from Automatic Variable topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right CHOICE is (a) When execution reaches the place of declaration of automatic variables

Best explanation: Only when the execution reaches the place where the automatic variable was DECLARED, the constructor is called. This is to ensure that the memory is not allocated if not NEEDED. The memory is allocated and then destroyed as soon as it goes out of scope.

21.

What values does uninitialized automatic variables contain?(a) Null value(b) Void value(c) Undefined/Garbage(d) Zero valueI have been asked this question in homework.Query is from Automatic Variable in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct OPTION is (c) Undefined/GARBAGE

The best I can explain: The automatic variable which are not initialized, contain garbage value. If we just DECLARE a variable and TRY to print its value, the RESULT is some unknown value. The value is garbage as that was not expected value.

22.

All variables declared within a block ____________________(a) Are not always automatic(b) Can be made non-automatic(c) Are static by default(d) Are automatic by defaultI had been asked this question during an online exam.The query is from Automatic Variable in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer» RIGHT answer is (d) Are AUTOMATIC by default

To EXPLAIN: The variables declared inside a block, are make automatic by default. This is to ensure that the variables get destroyed when not REQUIRED. The variables REMAIN live only till those are required, the life is dependent on the scope of a variable.
23.

The static variables of a function ________________(a) Are also automatic variables(b) Are not automatic variables(c) Are made automatic by default(d) Can be made automatic explicitlyThis question was posed to me in final exam.My doubt stems from Automatic Variable topic in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer» CORRECT answer is (b) Are not automatic variables

Easiest explanation - The STATIC members can’t be automatic. This is because the automatic variables are created and destroyed with each CALL to a specific function. But the static members REMAIN THROUGHOUT the execution of program once created.
24.

Where are the automatic variables stored if another function is called in between the execution of the program?(a) Heap(b) Queue(c) Stack(d) Temp variableI had been asked this question at a job interview.I need to ask this question from Automatic Variable in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct answer is (c) STACK

The best EXPLANATION: All the automatic variables are stored in a new stack entry as soon as their scope is created. If another function is called, the PRESENT data is saved in stack and new entry in stack is MADE for the called function. When the function returns, the automatic variables are used again from where those were left.

25.

If an automatic variable is created and then a function is called then ________________(a) The automatic variable created gets destroyed(b) The automatic variable doesn’t get destroyed(c) The automatic variable may or may not get destroyed(d) The automatic variable can’t be used in this caseI got this question in my homework.My doubt stems from Automatic Variable in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer» RIGHT choice is (b) The AUTOMATIC variable doesn’t get destroyed

To explain: The automatic VARIABLES are saved till the called FUNCTION gets executed. This is done so as to ensure that the program can continue its execution after the called function is returned. The automatic variables gets destroyed only if those go out of scope.
26.

Which among the following is true for automatic variables in general?(a) Automatic variables are invisible to called function(b) Automatic variables are always visible to the called function(c) Automatic variables can’t interact with the called function(d) Automatic variables can’t be variableI got this question during an interview.Enquiry is from Automatic Variable topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The CORRECT answer is (a) Automatic variables are invisible to called FUNCTION

The best explanation: The automatic variables are hidden from the called function. EVEN if PASSED by reference or address, the address of the variable is used and not the actual variable of calling function. Automatic variables can be const or variable.

27.

Scope of an automatic variable _______________(a) Is actually the whole program(b) Is actually never fixed(c) Is always equal to the whole program execution(d) Is actually function or block in which it is definedThe question was posed to me during an interview.Question is from Automatic Variable topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct answer is (d) Is actually function or BLOCK in which it is defined

The best I can EXPLAIN: The automatic variables scope is LIMITED only WITHIN the block or the function where those are defined. This is the property of all the automatic variables.

28.

The memory for automatic variables ___________________(a) Have to be allocated and deallocated explicitly(b) Are allocated and deallocated automatically(c) Is never actually allocated(d) Are never safeThe question was asked by my college professor while I was bunking the class.This interesting question is from Automatic Variable in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct choice is (B) Are allocated and DEALLOCATED automatically

To explain I would say: The memory is allocated and deallocated automatically for the automatic variables. As SOON as the variable comes in SCOPE, the memory is allocated. The variables are destroyed as soon as those go out of scope.

29.

What are automatic variables?(a) Global variables(b) Implicit/temporary variables(c) Local variables(d) System variablesThis question was addressed to me by my school teacher while I was bunking the class.This intriguing question comes from Automatic Variable in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer» RIGHT option is (c) Local variables

To EXPLAIN: The local variables are also known as automatic variables. The variables in any local SCOPE that are CREATED and destroyed as the program executes its scope.
30.

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 explicitlyThe question was asked in my homework.The doubt is from Delete Operator in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer» RIGHT option is (a) Can be DEFINED for each CLASS

The best I can EXPLAIN: 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.
31.

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 calledI got this question in homework.My doubt stems from Delete Operator topic in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct option is (a) Global delete OPERATOR is invoked

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

32.

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 functionI have been asked this question in an international level competition.My query is from Delete Operator in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right answer is (a) INVOKES function operator delete

Easiest 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.

33.

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 producedThe question was posed to me in examination.This key question is from Delete Operator topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right answer is (c) DELETE [] on an object and delete on object ARRAY

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.

34.

Which is the correct syntax to delete an array of objects?(a) delete [] objectName;(b) delete * objectName;(c) objectName[] delete;(d) delete objectName[];I got this question in my homework.This question is from Delete Operator in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right OPTION is (a) 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.

35.

Which is the correct syntax to delete a single object?(a) delete *objectName;(b) objectName delete;(c) delete objectName;(d) objectName *delete;This question was posed to me in an international level competition.I'd like to ask this question from Delete Operator topic in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct answer is (c) DELETE objectName;

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.

36.

How many variants of delete operator are available?(a) Only 1(b) Only 2(c) Only 3(d) Only 4I got this question in my homework.I want to ask this question from Delete Operator topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct answer is (b) Only 2

Easiest EXPLANATION - There are two VARIANTS of DELETE OPERATOR. ONE is for object deletion. Other is for deletion of object array.

37.

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 undefinedThe question was asked by my college director while I was bunking the class.Asked question is from Delete Operator topic in chapter Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct CHOICE is (d) Its value is undefined

The explanation is: 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.

38.

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 destructionThis question was posed to me in semester exam.This key question is from Delete Operator topic in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right choice is (b) Object destructor is called before deallocation

Best 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.

39.

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 valueThis question was addressed to me in a job interview.My query is from Delete Operator topic in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct option is (c) Can be USED on pointer with value 0

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

40.

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 arisesThe question was posed to me by my college director while I was bunking the class.The query is from Delete Operator in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct answer is (c) Then unpredictable ERRORS may arise

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.

41.

Which type of value has resulted from the delete operator?(a) void(b) void pointer(c) null pointer(d) nullThis question was addressed to me during an internship interview.The query is from Delete Operator in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer» CORRECT choice is (a) void

Easiest 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 defined for the delete operator.
42.

Does delete return any value?(a) Yes, positive value(b) Yes, negative value(c) Yes, zero value(d) NoI have been asked this question during an online interview.My query is from Delete Operator topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct answer is (d) No

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.

43.

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 applicableI got this question at a job interview.My enquiry is from Delete Operator topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right option is (a) It should be DELETED USING delete operator

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

44.

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 classThis question was addressed to me in a job interview.This intriguing question comes from Delete Operator topic in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct answer is (a) Deallocates a block of memory

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.

45.

How does compiler convert “::operator new” implicitly?(a) ::operator new( sizeof( type ) )(b) ::operator new( sizeof( ) )(c) new operator :: type sizeof( type )(d) new sizeof( type ) operatorThe question was asked in an international level competition.The question is from New Operator topic in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The CORRECT answer is (a) ::operator new( sizeof( type ) )

Best EXPLANATION: The compiler implicitly converts the syntax so that the instruction can be understood by the processor and PROPER MACHINE CODE can be generated. The conversion is done implicitly and no explicit syntax is required.

46.

If a new operator is defined for a class and still global new operator have to be used, which operator should be used with the keyword new?(a) Colon(b) Arrow(c) Dot(d) Scope resolutionI have been asked this question during an online exam.Query is from New Operator in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct ANSWER is (d) Scope resolution

The best I can EXPLAIN: As USUAL, scope resolution operator is used to get the scope of parent or the global entities. Hence we can use scope resolution operator with the NEW operator to call the global new operator even if new operator is defined for the class EXPLICITLY.

47.

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 implicitlyThis question was addressed to me in class test.The above asked question is from New Operator in division Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The correct choice is (a) INVOKES FUNCTION operator NEW

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

48.

The objects allocated using new operator ________________(a) Are destroyed when they go out of scope(b) Are not destroyed even if they go out of scope(c) Are destroyed anytime(d) Are not destroyed throughout the program executionThis question was posed to me in exam.Query is from New Operator in portion Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

The CORRECT OPTION is (b) Are not destroyed even if they go out of scope

To explain I would SAY: It is not necessary that the objects get destroyed when they go out of scope if allocated by using NEW operator. This is because new operator RETURNS a pointer to object that it had allocated. A suitable pointer with proper scope should be defined by the programmer explicitly.

49.

Which among the following is added in grammar of new operator?(a) Finalize(b) Arg(c) Initializer(d) AllocatorThe question was posed to me during a job interview.This question is from New Operator topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Right option is (c) INITIALIZER

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

50.

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 dataThis question was addressed to me during an interview.I'm obligated to ask this question of New Operator topic in section Memory Allocation & Scope of Variable of Object Oriented Programming

Answer»

Correct answer is (C) Can’t be SPECIFIED for ARRAYS

The EXPLANATION: 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.