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 correct?(a) Individual data members can’t be returned(b) Individual data members can be returned(c) Individual member functions can be returned from another function(d) Individual data members can only be passed by referenceI got this question in an interview for job.This key question is from Returning Objects topic in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right answer is (B) INDIVIDUAL data members can be returned

Easiest EXPLANATION - It is not MANDATORY to return the whole object. Instead we can return a specific data member value. But the return type given must match with the data type of the data being returned.

52.

If object is passed by reference ____________________(a) Temporary object is created(b) Temporary object is created inside the function(c) Temporary object is created for few seconds(d) Temporary object is not createdThis question was addressed to me in an international level competition.My query is from Returning Objects in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct answer is (d) Temporary object is not created

The BEST I can explain: The temporary object is not created. If object is returned by reference, a PARTICULAR MEMORY location will be DENOTED with another name and hence same address values will be used.

53.

Which error will be produced if a local object is returned by reference outside a function?(a) Out of memory error(b) Run time error(c) Compile time error(d) No errorThis question was addressed to me in homework.This intriguing question originated from Returning Objects in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT answer is (C) Compile time ERROR

Best explanation: If the local object is RETURNED outside the function then the compile-time error arises. While the program is being converted and the processes happening during compile time, the COMPILER won’t be able to resolve the statement.

54.

How many independent objects can be returned at same time from a function?(a) 1(b) 2(c) 3(d) 4I got this question in an online quiz.Enquiry is from Returning Objects in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct choice is (a) 1

For explanation: Only one object can be RETURNED at a time. This is because a function is only CAPABLE of RETURNING a SINGLE value at a time. THOUGH array of objects can be returned from a function.

55.

If an object is declared inside the function then ____________________ outside the function.(a) It can be returned by reference(b) It can’t be returned by reference(c) It can be returned by address(d) It can’t be returned at allThe question was asked in a job interview.Origin of the question is Returning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct OPTION is (b) It can’t be returned by REFERENCE

Explanation: The object which is declared inside the class can never be returned by reference. This is because the object will be destroyed as it goes out of SCOPE when the function is returned. The local variables get destroyed when function is returned HENCE the local objects can’t be returned by reference.

56.

Which is the correct syntax for defining a function which passes an object by reference?(a) className& functionName ( )(b) className* functionName( )(c) className-> functionName( )(d) &className functionName()This question was posed to me in an online interview.My question is from Returning Objects topic in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right answer is (a) className& functionName ( )

The best explanation: The function declaration must CONTAIN the CLASS name as return type. But, a & SYMBOL should be FOLLOWED by the class name. & INDICATES that the object being returned will be returned by reference.

57.

Which is the correct syntax for returning an object by value?(a) void functionName ( ){ }(b) object functionName( ) { }(c) class object functionName( ) { }(d) ClassName functionName ( ){ }The question was posed to me during an interview for a job.My doubt stems from Returning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» CORRECT option is (d) CLASSNAME functionName ( ){ }

EASY explanation - The class NAME itself should be the return type of the function. This NOTIFIES that the function will return an object of specified class type. Only the class name should be specified.
58.

Where the temporary objects (created while return by value) are created?(a) Outside the function scope(b) Within the function(c) Inside the main function(d) Inside the calling functionI had been asked this question in quiz.Enquiry is from Returning Objects in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct ANSWER is (b) Within the function

To explain I would say: The TEMPORARY object are created within the function and are INTENDED to return the VALUE for specific use. EITHER the object can be assigned to another object or be used directly if possible.

59.

Whenever an object is returned by value ____________________(a) A temporary object is created(b) Temporary object is not created(c) Temporary object may or may not be created(d) New permanent object is createdThis question was addressed to me in class test.My question is taken from Returning Objects in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct answer is (a) A temporary object is CREATED

The best explanation: A temporary object is created when an object is RETURNED by value. The temporary object is USED to copy the values to another object or to be used in some way. The object holds all the values of the data members of the object.

60.

In which of the following way(s) can the object be returned from a function?(a) Can only be returned by value(b) Can only be returned by reference(c) Can be returned either by value or reference(d) Can neither be returned by value nor by referenceThis question was addressed to me in homework.The question is from Returning Objects topic in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT answer is (c) Can be returned either by value or reference

The best explanation: The OBJECTS can be returned either by value or reference. There is no MANDATORY condition for the WAY it should be used. The way of returning object can be DECIDED based on the requirement.

61.

Pass by reference and pass by value can’t be done simultaneously in a single function argument list.(a) True(b) FalseThe question was posed to me in exam.This question is from Passing Object to Functions topic in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct choice is (B) False

The best explanation: There is no condition which specifies that only the reference pass or values pass is ALLOWED. The argument list can contain one reference pass and another VALUE pass. This helps to manipulate the objects with functions more EASILY.

62.

In which type is new memory location will be allocated?(a) Only in pass by reference(b) Only in pass by value(c) Both in pass by reference and value(d) Depends on the codeThis question was posed to me in my homework.This intriguing question comes from Passing Object to Functions in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right option is (b) Only in PASS by value

To EXPLAIN: The new memory location will be allocated only if the object is passed by value. Reference USES the same memory address and is denoted by ANOTHER NAME also. But in pass by value, another object is created and new memory space is allocated for it.

63.

Which among the following is true?(a) More than one object can’t be passed to a function(b) Any number of objects can be passed to a function(c) Objects can’t be passed, only data member values can be passed(d) Objects should be passed only if those are public in classI have been asked this question in an international level competition.This intriguing question originated from Passing Object to Functions topic in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct choice is (b) Any number of OBJECTS can be passed to a function

Easiest explanation - There is no restriction on passing the number of objects to a function. The operating SYSTEM or the compiler or environment MAY LIMIT the number of arguments. But there is no limit on number of objects till that limit.

64.

If the object is not to be passed to any function but the values of the object have to be used then?(a) The data members should be passed separately(b) The data members and member functions have to be passed separately(c) The values should be present in other variables(d) The object must be passedI had been asked this question in final exam.My doubt is from Passing Object to Functions in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right choice is (a) The data members should be PASSED separately

The best EXPLANATION: The data members can be passed separately. There is no need to pass WHOLE OBJECT, instead we can use the object to pass only the required values.

65.

What exactly is passed when an object is passed by reference?(a) The original object name(b) The original object class name(c) The exact address of the object in memory(d) The exact address of data membersI have been asked this question in an internship interview.I need to ask this question from Passing Object to Functions in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right choice is (c) The exact address of the object in memory

Explanation: The LOCATION of the object, that is, the exact memory location is PASSED, when the object is passed by REFERENCE. The pass by reference is ACTUALLY a reference to the object that the function uses with another name to the same memory location as the original object uses.

66.

Can data members be passed to a function using the object?(a) Yes, it can be passed only inside class functions(b) Yes, only if the data members are public and are being passed to a function outside the class(c) No, can’t be passed outside the class(d) No, can’t be doneThe question was posed to me in final exam.This intriguing question originated from Passing Object to Functions in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT choice is (B) Yes, only if the data members are public and are being passed to a function outside the CLASS

The best explanation: The data members can be passed with help of OBJECT but only if the member is public. The object will obviously be used outside the class. The object must have ACCESS to the data member so that its value or reference is used outside the class which is possible only if the member is public.

67.

If an object is passed by value, _________________(a) Temporary object is used in the function(b) Local object in the function is used(c) Only the data member values are used(d) The values are accessible from the original objectThis question was addressed to me in an online quiz.My doubt stems from Passing Object to Functions in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right choice is (b) Local OBJECT in the function is used

The explanation: When an object is called by values, copy CONSTRUCTOR is called and object is copied to the local object of the function which is mentioned in the argument list. The values GETS copied and are used from the local object. There is no need to access the original object again.

68.

What is the type of object that should be specified in the argument list?(a) Function name(b) Object name itself(c) Caller function name(d) Class name of objectThe question was posed to me during an interview for a job.Asked question is from Passing Object to Functions in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right choice is (d) CLASS NAME of object

Easy explanation - The type of object is the class itself. The class name have to be specified in order to pass the objects to a FUNCTION. This allows the program to create another object of same class or to USE the same object that was passed.

69.

Copy constructor definition requires __________________(a) Object to be passed by value(b) Object not to be passed to it(c) Object to be passed by reference(d) Object to be passed with each data member valueThis question was addressed to me in exam.I want to ask this question from Passing Object to Functions in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct OPTION is (c) OBJECT to be passed by reference

Easy explanation - The object MUST be passed by reference to a copy constructor. This is to avoid the out of memory ERROR. The constructors keeps calling itself, if not passed by reference, and GOES out of memory.

70.

Pass by reference of an object to a function _______________(a) Affects the object in called function only(b) Affects the object in prototype only(c) Affects the object in caller function(d) Affects the object only if mentioned with & symbol with every callI had been asked this question by my college director while I was bunking the class.My question is based upon Passing Object to Functions topic in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT choice is (c) Affects the object in CALLER FUNCTION

To explain: The original object in the caller function will get AFFECTED. The changes made in the called function will be same in the caller function object also.

71.

If object is passed by value ______________(a) Copy constructor is used to copy the values into another object in the function(b) Copy constructor is used to copy the values into temporary object(c) Reference to the object is used to access the values of the object(d) Reference to the object is used to created new object in its placeI have been asked this question during an interview.My question is from Passing Object to Functions topic in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct option is (a) Copy constructor is USED to copy the VALUES into another OBJECT in the function

Explanation: The copy constructor is used. This constructor is used to copy the values into a new object which will contain all the values same as that of the object being passed but any CHANGES made to the newly created object will not affect the ORIGINAL object.

72.

Which symbol should be used to pass the object by reference in C++?(a) &(b) @(c) $(d) $ or &The question was posed to me in examination.The doubt is from Passing Object to Functions topic in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT option is (a) &

For explanation: The OBJECT to be passed by REFERENCE to the function should be preceded by & symbol in the argument list syntax of the function. This indicates the compiler not to use NEW object. The same object which is being passed have to be used.

73.

The object ________________(a) Can be passed by reference(b) Can be passed by value(c) Can be passed by reference or value(d) Can be passed with referenceThe question was posed to me in homework.I would like to ask this question from Passing Object to Functions in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct answer is (c) Can be PASSED by reference or value

The explanation: The OBJECTS can be passed by reference if required to use the same object. The VALUES can be passed so that the main object REMAINS same and no changes are made to it if the function makes any changes to the values being passed.

74.

Passing object to a function _______________(a) Can be done only in one way(b) Can be done in more than one ways(c) Is not possible(d) Is not possible in OOPThe question was posed to me in exam.This question is from Passing Object to Functions topic in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT option is (b) Can be DONE in more than one ways

The best I can explain: The objects can be passed to the functions and this REQUIRES OOP concept because objects are main part of OOP. The objects can be passed in more than one WAY to a function. The passing depends on how the OBJECT have to be used.