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.

Which is the correct syntax for declaring the type of this in a member function?(a) classType [cv-qualifier-list] *const this;(b) classType const[cv-qualifier-list] *this;(c) [cv-qualifier-list]*const classType this;(d) [cv-qualifier-list] classType *const this;The question was asked by my school principal while I was bunking the class.This is a very interesting question from This Pointer topic in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right choice is (d) [cv-qualifier-list] classType *const this;

Easy explanation - The syntax contains the cv-qualifier-list that can be determined from the member function DECLARATORY that can be either const or VOLATILE or can be made both. Hence we write it as list. classType denotes the name of class to MENTION to which class does the OBJECT BELONG to. And *const this denotes that the this pointer is having a constant value.

2.

Which among the following is/are type(s) of this pointer?(a) const(b) volatile(c) const or volatile(d) intI had been asked this question in quiz.Question is from This Pointer in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT answer is (c) CONST or volatile

The explanation is: The this pointer can be declared const or volatile. This DEPENDS on NEED of PROGRAM and type of code. This is just an additional feature.

3.

This pointer can be used directly to ___________(a) To manipulate self-referential data structures(b) To manipulate any reference to pointers to member functions(c) To manipulate class references(d) To manipulate and disable any use of pointersThis question was posed to me during an interview for a job.This interesting question is from This Pointer topic in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct ANSWER is (a) To manipulate self-referential data STRUCTURES

Easiest EXPLANATION - This is a FEATURE provided, that can be used directly. The manipulation of self-referential data structures is just an APPLICATION of this feature. Other conditions fails as this pointer doesn’t deal with those things.

4.

Earlier implementations of C++ ___________________(a) Never allowed assignment to this pointer(b) Allowed no assignment to this pointer(c) Allowed assignments to this pointer(d) Never allowed assignment to any pointerThe question was posed to me in quiz.This question is from This Pointer in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT OPTION is (c) Allowed assignments to this pointer

Easy explanation - The EARLIER, most initial versions of C++ used to allow assignments to this pointers. That used to allow modifications of this pointer. Later that feature GOT DISABLED.

5.

The this pointers _____________________(a) Are modifiable(b) Can be assigned any value(c) Are made variables(d) Are non-modifiableI have been asked this question in an interview.Enquiry is from This Pointer topic in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct option is (d) Are non-modifiable

Explanation: The this pointer is non modifiable. This is because the address of any object remains CONSTANT throughout its LIFE TIME. Hence the address must not be changed OTHERWISE wrong members of invalid addresses might get accessed.

6.

Which syntax doesn’t execute/is false when executed?(a) if(&object != this)(b) if(&function !=object)(c) this.if(!this)(d) this.function(!this)The question was posed to me in my homework.I would like to ask this question from This Pointer topic in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct OPTION is (a) if(&object != this)

Explanation: The condition becomes false when EXECUTED and hence doesn’t executes. This is the case where this pointer can GUARD itself from the self-reference. Here if the ADDRESS of the object doesn’t match with this pointer that means the object doesn’t refer itself.

7.

Which among the following is true?(a) This pointer can be used to guard against any kind of reference(b) This pointer can be used to guard against self-reference(c) This pointer can be used to guard from other pointers(d) This pointer can be used to guard from parameter referencingThe question was asked by my college director while I was bunking the class.The origin of the question is This Pointer in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» RIGHT answer is (b) This pointer can be used to GUARD against self-reference

For explanation: The this pointer can be used to guard itself whenever self-reference is used. This ALLOWS accidental ADDRESS ACCESS. And accidental modification of data.
8.

The address of the object _________________(a) Can’t be accessed from inside the function(b) Can’t be accessed in the program(c) Is available inside the member function using this pointer(d) Can be accessed using the object name inside the member functionThis question was posed to me during an internship interview.Asked question is from This Pointer in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct option is (c) Is available inside the member function using this pointer

Best explanation: The ADDRESS of the OBJECT with RESPECT to which the member functions are being called, are stored in this pointer. This pointer is hence used whenever there are MEMBERS with same name as those of the VARIABLES inside the function.

9.

Which is the correct interpretation of the member function call from an object, object.function(parameter);(a) object.function(&this, parameter)(b) object(&function,parameter)(c) function(&object,&parameter)(d) function(&object,parameter)I had been asked this question during a job interview.My question is from This Pointer topic in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct ANSWER is (d) function(&object,parameter)

The best explanation: The function name is SPECIFIED first and then the parameter lists. The parameter list is included with the object name along with & symbol. This denotes that the ADDRESS of the object is being PASSED as an argument.

10.

Whenever non-static member functions are called _______________(a) Address of the object is passed implicitly as an argument(b) Address of the object is passed explicitly as an argument(c) Address is specified globally so that the address is not used again(d) Address is specified as return type of the functionI had been asked this question in quiz.The query is from This Pointer topic in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT choice is (a) Address of the OBJECT is passed implicitly as an argument

The EXPLANATION is: The address is passed implicitly as an argument to the function. This doesn’t have to be passed explicitly. The address is passed, of the object which is CALLING the non-static member function.

11.

The result of sizeof() function __________________(a) Includes space reserved for this pointer(b) Includes space taken up by the address pointer by this pointer(c) Doesn’t include the space taken by this pointer(d) Doesn’t include space for any data memberThe question was posed to me during an interview.The question is from This Pointer in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct option is (C) Doesn’t include the space TAKEN by this pointer

The BEST I can EXPLAIN: The space taken by this pointer is not reflected in by the sizeof() operator. This is because object’s this pointer is not part of object itself. This is a cross verification for the concept stating that this pointer doesn’t TAKE any space in the object.

12.

An object’s this pointer _____________________(a) Isn’t part of class(b) Isn’t part of program(c) Isn’t part of compiler(d) Isn’t part of object itselfI had been asked this question in my homework.Enquiry is from This Pointer topic in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct option is (d) Isn’t part of object itself

To explain: The object’s this pointer being called are not part of the object itself. This can be cross verified by CHECKING that it doesn’t take up any SPACE for the DATA to be stored or POINTED.

13.

The this pointer is accessible __________________(a) Within all the member functions of the class(b) Only within functions returning void(c) Only within non-static functions(d) Within the member functions with zero argumentsI had been asked this question in final exam.Asked question is from This Pointer in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»
14.

Which among the following is true?(a) this pointer is passed implicitly when member functions are called(b) this pointer is passed explicitly when member functions are called(c) this pointer is passed with help of pointer member functions are called(d) this pointer is passed with help of void pointer member functions are calledThe question was posed to me in homework.Asked question is from This Pointer in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right ANSWER is (a) this pointer is passed implicitly when member functions are called

Easy explanation - When an object CALLS some member function, it implicitly PASSES itself as an argument. This allows the compiler to KNOW which member should be used for the PURPOSES. This also allows to reduce the ambiguity among the variable and data member names.

15.

Which is the pointer which denotes the object calling the member function?(a) Variable pointer(b) This pointer(c) Null pointer(d) Zero pointerThis question was posed to me in class test.My query is from This Pointer in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right option is (b) This POINTER

The explanation: The pointer which denotes the object CALLING the member function is known as this pointer. The this pointer is USUALLY USED when there are members in the function with same name as those of the class members.

16.

References to object are same as pointers of object.(a) True(b) FalseI got this question in an online quiz.I would like to ask this question from Pointer to Objects topic in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right choice is (b) False

Easy explanation - The REFERENCES are made to object when the object is created and initialized with another object without calling any CONSTRUCTOR. But the object pointer must be DECLARED explicitly using * symbol that will be capable of STORING some address. Hence both are DIFFERENT.

17.

What should be done to prevent changes that may be made to the values pointed by the pointer?(a) Usual pointer can’t change the values pointed(b) Pointer should be made virtual(c) Pointer should be made anonymous(d) Pointer should be made constI have been asked this question by my school principal while I was bunking the class.Query is from Pointer to Objects in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right ANSWER is (d) Pointer should be MADE const

The explanation: The pointer should be declared as a const type. This prevents the pointer to change any value that is being pointed from it. This is a feature that is made to access the VALUES USING pointer but to make sure that pointer doesn’t change those values accidently.

18.

How can the address stored in the pointer be retrieved?(a) Using * symbol(b) Using $ symbol(c) Using & symbol(d) Using @ symbolThe question was asked in examination.I want to ask this question from Pointer to Objects in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» RIGHT CHOICE is (C) USING & symbol

The BEST I can explain: The & symbol must be used. This should be done such that the object should be preceded by & symbol and then the address should be stored in another variable. This is done to get the address where the object is stored.
19.

If a pointer to an object is created and the object gets deleted without using the pointer then __________(a) It becomes void pointer(b) It becomes dangling pointer(c) It becomes null pointer(d) It becomes zero pointerI had been asked this question in an online interview.The question is from Pointer to Objects in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right choice is (b) It becomes DANGLING pointer

The explanation: When the address POINTED by the object pointer gets deleted, the pointer now POINTS to an invalid address. Hence it becomes a dangling pointer. It can’t be null or VOID pointer since it doesn’t point to any specific LOCATION.

20.

Which is the correct syntax to call a member function using pointer?(a) pointer->function()(b) pointer.function()(c) pointer::function()(d) pointer:function()This question was posed to me during an interview.My question is from Pointer to Objects topic in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT OPTION is (a) POINTER->function()

Easy explanation - The pointer should be mentioned followed by the arrow OPERATOR. Arrow operator is APPLICABLE only with the pointers. Then the function name should be mentioned that is to be called.

21.

Which among the following is true?(a) The pointer to object can hold address only(b) The pointer can hold value of any type(c) The pointer can hold only void reference(d) The pointer can’t hold any valueThe question was asked in an interview for job.Origin of the question is Pointer to Objects topic in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct option is (a) The pointer to OBJECT can hold ADDRESS only

Explanation: The pointer to an object can hold only the addresses. Address of any other object of same class. This allows the programmer to link more than one OBJECTS if REQUIRED.

22.

Is name of an array of objects is also a pointer to object?(a) Yes, always(b) Yes, in few cases(c) No, because it represents more than one object(d) No, neverThe question was asked in an online interview.I'm obligated to ask this question of Pointer to Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right ANSWER is (a) YES, always

Best EXPLANATION: The ARRAY name represents a pointer to the OBJECT. The name alone can represent the starting address of the array. But that also represents an array which is in turn stored in a pointer.

23.

Pointer to a base class can be initialized with the address of derived class, because of _________(a) derived-to-base implicit conversion for pointers(b) base-to-derived implicit conversion for pointers(c) base-to-base implicit conversion for pointers(d) derived-to-derived implicit conversion for pointersI have been asked this question by my school teacher while I was bunking the class.I want to ask this question from Pointer to Objects topic in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right answer is (a) derived-to-base IMPLICIT CONVERSION for pointers

The explanation is: It is an implicit rule defined in most of the programming languages. It PERMITS the programmer to DECLARE a pointer to the derived class from a base class pointer. In this way the programmer doesn’t have to declare object for derived class each TIME it is required.

24.

Can pointers to object access the private members of the class?(a) Yes, always(b) Yes, only if it is only pointer to object(c) No, because objects can be referenced from another objects too(d) No, neverI had been asked this question in homework.The query is from Pointer to Objects topic in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct choice is (d) No, never

Explanation: The POINTERS to an object can never access the private MEMBERS of the class OUTSIDE the class. The object can indirectly USE those private members using member FUNCTIONS which are public in the class.

25.

What is the size of an object pointer?(a) Equal to size of any usual pointer(b) Equal to size of sum of all the members of object(c) Equal to size of maximum sized member of object(d) Equal to size of voidI had been asked this question during an online interview.My enquiry is from Pointer to Objects in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT option is (a) Equal to SIZE of any USUAL pointer

To explain: The size of OBJECT pointer is same as that of any usual pointer. This is because only the address have to be stored. There are no values to be stored in the pointer.

26.

A pointer _________________(a) Can point to only one object at a time(b) Can point to more than one objects at a time(c) Can point to only 2 objects at a time(d) Can point to whole class objects at a timeI have been asked this question in exam.This intriguing question comes from Pointer to Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The CORRECT answer is (a) Can point to only one object at a TIME

Easiest EXPLANATION - The object pointer can point to only one object at a time. The pointer will be able to store only one ADDRESS at a time. Hence only one object can be referred.

27.

If pointer to an object is declared __________(a) It can store any type of address(b) It can store only void addresses(c) It can only store address of integer type(d) It can only store object address of class type specifiedI have been asked this question in an interview for internship.The query is from Pointer to Objects topic in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right option is (d) It can only store object address of class type specified

Explanation: The address of only the specified class type can get their address STORED in the object pointer. The addresses doesn’t DIFFER but they do differ for the AMOUNT and type of memory required for objects of different classes. HENCE same class object pointer should be used.

28.

How does compiler decide the intended object to be used, if more than one object are used?(a) Using object name(b) Using an integer pointer(c) Using this pointer(d) Using void pointerThe question was asked by my school principal while I was bunking the class.The above asked question is from Pointer to Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right option is (C) Using this pointer

To explain I WOULD say: This pointer denotes the OBJECT, in which it is being used. If member function is called with respect to ONE object then this pointer refers to the same object members. It can be used when members with same name are INVOLVED.

29.

Which operator should be used to access the members of the class using object pointer?(a) Dot operator(b) Colon to the member(c) Scope resolution operator(d) Arrow operatorI had been asked this question by my school teacher while I was bunking the class.I'd like to ask this question from Pointer to Objects in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right option is (d) ARROW operator

The best EXPLANATION: The MEMBERS can be ACCESSED from the object POINTER by using arrow operator. The arrow operator can be used only with the pointer of class type. If simple object is declared, it must use dot operator to access the members.

30.

Which is correct syntax for declaring pointer to object?(a) className* objectName;(b) className objectName;(c) *className objectName;(d) className objectName();I had been asked this question in an internship interview.I'm obligated to ask this question of Pointer to Objects in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct option is (a) className* objectName;

The best I can explain: The syntax MUST contain * SYMBOL after the className as the type of object. This DECLARES an object POINTER. This can store address of any object of the specified CLASS.

31.

Which language among the following doesn’t allow pointers?(a) C++(b) Java(c) Pascal(d) CThe question was posed to me during an interview.My enquiry is from Pointer to Objects in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct choice is (b) Java

The explanation: The concept of POINTERS is not SUPPORTED in Java. The feature is not given in the LANGUAGE but can be USED in some ways explicitly. Though this pointer is supported by java too.

32.

Assigning objects takes place while passing the arguments.(a) True(b) FalseThis question was posed to me during an interview.Asked question is from Assigning Objects topic in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» CORRECT answer is (b) False

Explanation: The actual assignment doesn’t take place as the OBJECT might have got passed by REFERENCE. Also even if not by reference, the COPY CONSTRUCTOR is called to copy the values into the new object and not exactly the assignment operator.
33.

Which among the following is true?(a) We can use direct assignment for any object(b) We can use direct assignment only for different class objects(c) We must not use direct assignment(d) We can use direct assignment to same class objectsThis question was posed to me during an internship interview.My doubt stems from Assigning Objects in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct choice is (d) We can use direct assignment to same class objects

For EXPLANATION: The direct assignment can be used with the same class objects. There is no RESTRICTION on them. But better if the program have a PREDEFINED COPY assignment OPERATOR.

34.

Assigning reference to an object _________________(a) Will create another copy of the object(b) Will create two different copies of the object(c) Will not create any other copy of the object(d) Will not refer to the objectThe question was posed to me in an interview for internship.This interesting question is from Assigning Objects topic in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» CORRECT option is (c) Will not create any other copy of the OBJECT

For EXPLANATION: When an object is assigned with another object. Same MEMORY location is used. There is no other copy of the object created.
35.

We can assign ______________________(a) Value of one reference variable to another(b) Value of any object to another(c) Value of any type to any object(d) Value of non – reference to another referenceThe question was asked in a job interview.Origin of the question is Assigning Objects in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» RIGHT answer is (a) VALUE of ONE reference variable to ANOTHER

The best I can explain: Only the reference value can be assigned to another reference value. This is because both deal with the address. There is no TYPE mismatch hence we can assign them.
36.

How to make more than one object refer to the same object?(a) Initialize it to null(b) Initialize the object with another at declaration(c) Use constructor to create new object(d) Assign the address directlyThe question was asked at a job interview.I'd like to ask this question from Assigning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right OPTION is (b) Initialize the object with another at declaration

Easiest EXPLANATION - The object must get initialized with another object at time of declaration only. We don’t have to CREATE a new object we just have to get name of new object because there after same address will be REFERRED.

37.

If more than one object refer to the same address, any changes made __________(a) Can be made visible to specific objects(b) Will be specific to one object only(c) From any object will be visible in all(d) Doesn’t changes the values of all objectsI had been asked this question in an online quiz.My question is based upon Assigning Objects in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right choice is (c) From any object will be visible in all

Easiest explanation - At a memory ADDRESS, only ONE object can be referenced. All the other objects which refer to the same memory address MAKE CHANGES for all of the objects referring that address.

38.

Use of assignment operator ____________________(a) Changes its use, when used at declaration and in normal assignment(b) Doesn’t changes its use, whatever the syntax might be(c) Assignment takes place in declaration and assignment syntax(d) Doesn’t work in normal syntax, but only with declarationI have been asked this question in an online quiz.The origin of the question is Assigning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» RIGHT choice is (a) Changes its use, when used at declaration and in NORMAL ASSIGNMENT

Easiest EXPLANATION - The assignment operator if used at declaration then it uses copy constructor for the copying of objects. If used in simple assignment syntax then it uses copy assignment function.
39.

How many objects can be assigned to a single address?(a) Only 1(b) At most 7(c) At most 3(d) As many as requiredThis question was addressed to me during an internship interview.Enquiry is from Assigning Objects in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct answer is (d) As MANY as required

Easiest explanation - The memory ADDRESS can be referenced by more than one OBJECT. There is no maximum number DEFINED. Any number of objects can REFERENCE to the same address.

40.

In copy constructor definition, if non const values are accepted only ________(a) Only const objects will be accepted(b) Only non – const objects are accepted(c) Only const members will not get copied(d) Compiler generates an errorThe question was asked during an online interview.This intriguing question originated from Assigning Objects in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct answer is (B) Only NON – const objects are accepted

The best EXPLANATION: Only the non – const objects will be accepted by the compiler. If a const object is passed, the compiler produces an error. To REDUCE that, we use const ARGUMENT in definition, so that both const and non – const objects are accepted.

41.

Declaring a copy constructor doesn’t suppresses the compiler generated copy assignment operator.(a) True(b) FalseI got this question in an interview.I need to ask this question from Assigning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct OPTION is (a) True

To explain: Even if the PROGRAMMER doesn’t define or even if they define the COPY constructor. The compiler STILL generates a copy ASSIGNMENT operator. It doesn’t gets suppressed.

42.

If programmer doesn’t define any copy assignment operator then ____________________(a) Compiler gives an error(b) Program fails at run time(c) Compiler gives an implicit definition(d) Compiler can’t copy the member valuesI had been asked this question by my school principal while I was bunking the class.This interesting question is from Assigning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right answer is (c) Compiler gives an implicit definition

The explanation is: While DEFINING a COPY constructor, we use REFERENCE const parameter, those are used for the assignment. The assignment operator may or may not be defined by the programmer, if not, compiler implicitly defines member WISE copy assignment operator.

43.

How the argument passed to a function get initialized?(a) Assigned using copy constructor at time of passing(b) Copied directly(c) Uses addresses always(d) Doesn’t get initializedThe question was asked during an online exam.This question is from Assigning Objects topic in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right ANSWER is (a) ASSIGNED using copy constructor at time of passing

The explanation: The arguments get INITIALIZED using the copy constructor. There is a need of assigning the VALUE of all the members of an OBJECT to the local object of the function.

44.

If an object is created and another object is assigned to it, then ________________(a) Copy constructor is called to copy the values(b) Object is copied directly to the object(c) Reference to another object is created(d) The new object is initialized to null valuesI got this question during an online exam.Asked question is from Assigning Objects topic in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» CORRECT option is (c) Reference to another OBJECT is created

The BEST I can explain: The new object created, refers to the same address of the PREVIOUSLY created object. Now whenever new object changes any data member value, it will affect the previously existing object.
45.

When value of an object is assigned to another object ________________(a) It becomes invalid statement(b) Its values gets copied into another object(c) Its values gets address of the existing values(d) The compiler doesn’t execute that statementI had been asked this question by my school principal while I was bunking the class.The origin of the question is Assigning Objects topic in section Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

The correct option is (b) Its VALUES gets copied into another object

The best EXPLANATION: The values GET copied to another object. No address is assigned to the object values. This is USES copy constructor to copy the values.

46.

Why temporary object is not created in return by reference?(a) Because compiler can’t create temporary objects(b) Because the temporary object is created within the function(c) Because return by reference just make the objects points to values memory location(d) Because return by reference just make the object point to nullThe question was asked in final exam.Asked question is from Returning Objects topic in division Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right option is (c) Because RETURN by reference just MAKE the OBJECTS points to values memory location

To explain: A reference to the memory location where the returned object is stored is made. This allows the NEW object which TAKES the return value, point to the memory location and hence access the same values.

47.

If an object is being returned by value then __________________________(a) Its member values are made constant(b) Its member values have to be copied individually(c) Its member values are not used(d) Its member values are copied using copy constructorI had been asked this question during a job interview.I'm obligated to ask this question of Returning Objects topic in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Right answer is (d) Its member values are copied using copy CONSTRUCTOR

The best I can explain: When an object is returned by value, it will be returned to another object or will be DIRECTLY USED. Still in all the conditions the copy constructor will be used to copy all the values from the TEMPORARY object that gets created.

48.

Which among the following is true?(a) Two objects can point to the same memory location(b) Two objects can never point to the same memory location(c) Objects not allowed to point at a location already occupied(d) Objects can’t point to any addressThe question was asked in my homework.The query is from Returning Objects in portion Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» RIGHT answer is (a) TWO objects can point to the same memory location

The best I can EXPLAIN: When an object is created and instead of CALLING a constructor, another object is assigned to it. Both the objects point to the same memory location. This can be illustrated with help of return by reference.
49.

If an object is passed by reference to a function then it must be returned by reference.(a) True(b) FalseThis question was addressed to me in an internship interview.My doubt is from Returning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer» RIGHT answer is (b) False

The best EXPLANATION: It is not compulsory to RETURN the object in the same way as it was passed. If the object is passed by reference then there is actually no NEED to return the object. Because the changes made inside the function will be visible on the original object of caller function also.
50.

Can we return an array of objects?(a) Yes, always(b) Ye, only if objects are having same values(c) No, because objects contain many other values(d) No, because objects are single entityThis question was addressed to me during a job interview.This interesting question is from Returning Objects in chapter Assigning Object, Pointer to Objects, Passing and Returning Object of Object Oriented Programming

Answer»

Correct choice is (a) Yes, always

To explain: The Object array can be RETURNED from a function. This can be done by PUTTING a className* as the return type of the function. This makes the return type to ACCEPT an array of OBJECTS in return.