You are on page 1of 40

Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...

sanfoundry.com

Object Oriented Programming


Interview Questions and Answers
for Experienced
by Manish
7-9 minutes

This set of Object Oriented Programming Interview


Questions and Answers for Experienced people focuses on
“Passing Object to Functions”.

1. 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 OOP
View Answer

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

2. The object ________________


a) Can be passed by reference

1 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...

b) Can be passed by value


c) Can be passed by reference or value
d) Can be passed with reference
View Answer

Answer: c
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.

3. Which symbol should be used to pass the object by


reference in C++?
a) &
b) @
c) $
d) $ or &
View Answer

Answer: a
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.

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

2 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...

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 place
View Answer

Answer: a
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.

5. 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 call
View Answer

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

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

3 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...

d) Object to be passed with each data member value


View Answer

Answer: c
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.

7. What is the type of object that should be specified in


argument list?
a) Function name
b) Object name itself
c) Caller function name
d) Class name of object
View Answer

Answer: d
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.

8. 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 object
View Answer

Answer: b
Explanation: When an object is called by values, copy
constructor is called and object is copied to the local object

4 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...

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.

9. 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 done
View Answer

Answer: b
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.

10. 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 members
View Answer

Answer: c
Explanation: The location of the object, that is, the exact
memory location is passed, when the object is passed by

5 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...

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.

11. 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 passed
View Answer

Answer: a
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.

12. 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 class
View Answer

Answer: b
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.

6 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...

13. What will be the output if all necessary code is included


(Header files and main function)?

void test (Object &y)


{
y = "It is a string";
}
void main()
{
Object x = null;
test (x);
System.out.println (x);
}

a) Run time error


b) Compiler time error
c) Null
d) It is a string
View Answer

Answer: d
Explanation: This is because the x object is passed by
reference. The changes made inside the function will be
applicable to original function too.

14. 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 code
View Answer

Answer: b

7 of 8 3/19/18, 10:05 AM
Object Oriented Programming Interview Questi... about:reader?url=https://www.sanfoundry.com/...

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

15. Pass by reference and pass by value can’t be done


simultaneously in a single function argument list.
a) True
b) False
View Answer

Answer: b
Explanation: There is no condition which specifies that only
the reference pass or values pass is allowed. The argument
list ca contain one reference pass and another value pass.
This helps to manipulate the objects with functions more
easily.

Sanfoundry Global Education & Learning Series –


Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming for


Interviews, here is complete set of 1000+ Multiple Choice
Questions and Answers.

8 of 8 3/19/18, 10:05 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

sanfoundry.com

Returning Objects Questions and


Answers
by Manish
7-9 minutes

This set of Object Oriented Programming (OOPs) Multiple


Choice Questions & Answers (MCQs) focuses on
“Returning Objects”.

1. 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 reference
View Answer

Answer: c
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.

2. Whenever an object is returned by value


____________________
a) A temporary object is created

1 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

b) Temporary object is not created


c) Temporary object may or may not be created
d) New permanent object is created
View Answer

Answer: a
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.

3. 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 function
View Answer

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

4. Which is the correct syntax for returning an object by


value?
a) void functionName ( ){ }
b) object functionName( ) { }
c) class object functionName( ) { }
d) ClassName functionName ( ){ }

2 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

View Answer

Answer: d
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.

5. 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()
View Answer

Answer: a
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.

6. 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 all
View Answer

Answer: b
Explanation: The object which is declared inside the class
can never be returned by reference. This is because the

3 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

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.

7. How many independent objects can be returned at same


time from a function?
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: a
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.

8. 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) Compiler time error
d) No error
View Answer

Answer: c
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

4 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

the statement.

9. 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 created
View Answer

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

10. 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
reference
View Answer

Answer: b
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.

11. Can we return an array of objects?


a) Yes, always
b) Ye, only if objects are having same values

5 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

c) No, because objects contain many other values


d) No, because objects are single entity
View Answer

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

12. If an object is passed by reference to a function then it


must be returned by reference.
a) True
b) False
View Answer

Answer: b
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.

13. 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 address
View Answer

Answer: a

6 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

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

14. 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 constructor
View Answer

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

15. 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
null
View Answer

Answer: c
Explanation: A reference to the memory location where the

7 of 8 3/19/18, 10:06 AM
Returning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

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.

Sanfoundry Global Education & Learning Series –


Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming


(OOPs), here is complete set of 1000+ Multiple Choice
Questions and Answers.

8 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

sanfoundry.com

Assigning Objects Questions and


Answers
by Manish
7-8 minutes

This set of Object Oriented Programming (OOPs) Multiple


Choice Questions & Answers (MCQs) focuses on
“Assigning Objects”.

1. 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 statement
View Answer

Answer: b
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.

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

1 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

c) Reference to another object is created


d) The new object is initialized to null values
View Answer

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

3. 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 initialized
View Answer

Answer: a
Explanation: The arguments get initialized using the copy
constructor. There is need of assigning the value of all the
members of an object to the local object of the function.

4. Predict the output of the program.

class A
{
public int i;
};
void main()
{
A x;
A y=x;
x.i=10;

2 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

y.i=20;
y.i++;
y.i=20;
cout&l;<tx.i;
}

a) 10
b) 20
c) 21
d) 0
View Answer

Answer: b
Explanation: The expected output may be 10 because the
value of member of object x is printed. But when object x is
assigned to y, y points to the same address where x is
stored. So actually both objects x and y point to the same
location and refers to the same object.

5. 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 values
View Answer

Answer: c
Explanation: 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

3 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

defines member wise copy assignment operator.

6. Declaring a copy constructor doesn’t suppresses the


compiler generated copy assignment operator.
a) True
b) False
View Answer

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

7. 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 error
View Answer

Answer: b
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.

8. How many objects can be assigned to a single address?


a) Only 1
b) At most 7
c) At most 3

4 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

d) As many as required
View Answer

Answer: d
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.

9. 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 declaration
View Answer

Answer: a
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.

10. 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 objects
View Answer

Answer: c

5 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

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.

11. 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 directly
View Answer

Answer: b
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.

12. 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 reference
View Answer

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

13. Assigning reference to an object _________________

6 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

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 object
View Answer

Answer: c
Explanation: When an object is assigned with another
object. Same memory location is used. There is no other
copy of the object created.

14. 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 objects
View Answer

Answer: d
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.

15. Assigning objects takes place while passing the


arguments.
a) True
b) False
View Answer

Answer: b
Explanation: The actual assignment doesn’t take place as

7 of 8 3/19/18, 10:06 AM
Assigning Objects Questions and Answers about:reader?url=https://www.sanfoundry.com/...

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.

Sanfoundry Global Education & Learning Series –


Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming


(OOPs), here is complete set of 1000+ Multiple Choice
Questions and Answers.

8 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...

sanfoundry.com

Object Oriented Programming


Assessment Questions
by Manish
7-9 minutes

This set of Object Oriented Programming Assessment


Questions and Answers focuses on “Pointer to Objects”.

1. Which language among the following doesn’t allow


pointers?
a) C++
b) Java
c) Pascal
d) C
View Answer

Answer: b
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.

2. Which is correct syntax for declaring pointer to object?


a) className* objectName;
b) className objectName;
c) *className objectName;

1 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...

d) className objectName();
View Answer

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

3. 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 operator
View Answer

Answer: d
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.

4. 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 pointer
View Answer

Answer: c

2 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...

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

5. 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 specified
View Answer

Answer: d
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.

6. What is the size of 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 void
View Answer

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

7. A pointer _________________

3 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...

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 time
View Answer

Answer: a
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.

8. 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 pointers
View Answer

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

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

4 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...

d) No, never
View Answer

Answer: d
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.

9. 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, never
View Answer

Answer: a
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.

10. 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 value
View Answer

Answer: a
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

5 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...

required.

11. Which is the correct syntax to call a member function


using pointer?
a) pointer->function()
b) pointer.function()
c) pointer::function()
d) pointer:function()
View Answer

Answer: a
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.

12. If pointer to an object is created and the object gets


deleted without using the pointer:
a) It becomes void pointer
b) It becomes dangling pointer
c) It becomes null pointer
d) It becomes zero pointer
View Answer

Answer: b
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.

13. How can the address stored in the pointer be retrieved?


a) Using * symbol

6 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...

b) Using $ symbol
c) Using & symbol
d) Using @ symbol
View Answer

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

14. 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 const
View Answer

Answer: d
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.

15. References to object are same as pointers of object.


a) True
b) False
View Answer

Answer: b
Explanation: The references are made to object when the

7 of 8 3/19/18, 10:06 AM
Object Oriented Programming Assessment Ques... about:reader?url=https://www.sanfoundry.com/...

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.

Sanfoundry Global Education & Learning Series –


Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming


Assessment Questions, here is complete set of 1000+
Multiple Choice Questions and Answers.

8 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...

sanfoundry.com

This Pointer - Object Oriented


Programming Questions and
Answers
by Manish
7-9 minutes

This set of Object Oriented Programming (OOPs) Multiple


Choice Questions & Answers (MCQs) focuses on “This
Pointer”.

1. Which is the pointer which denotes the object calling the


member function?
a) Variable pointer
b) This pointer
c) Null pointer
d) Zero pointer
View Answer

Answer: b
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.

2. Which among the following is true?


a) this pointer is passed implicitly when member functions

1 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...

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 called
View Answer

Answer: a
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.

3. 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 arguments
View Answer

Answer: c
Explanation: The this pointer is available only within the
non-static member functions of a class. If the member
function is static, it will be common to all the objects and
hence a single object can’t refer to those functions
independently.

4. An object’s this pointer _____________________


a) Isn’t part of class

2 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...

b) Isn’t part of program


c) Isn’t part of compiler
d) Isn’t part of object itself
View Answer

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

5. 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 member
View Answer

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

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

3 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...

d) Address is specified as return type of the function


View Answer

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

7. 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)
View Answer

Answer: d
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.

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 function
View Answer

Answer: c
Explanation: The address of the object with respect to

4 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...

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 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
referencing
View Answer

Answer: b
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.

10. 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)
View Answer

Answer: a
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.

5 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...

11. The this pointers _____________________


a) Are modifiable
b) Can be assigned any value
c) Are made variables
d) Are non-modifiable
View Answer

Answer: d
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.

12. 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 pointer
View Answer

Answer: c
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.

13. 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 pointers

6 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...

View Answer

Answer: a
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.

14. Which among the following is/are type(s) of this pointer?


a) const
b) volatile
c) const or volatile
d) int
View Answer

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

15. Which is the correct syntax for declaring 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;
View Answer

Answer: d
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

7 of 8 3/19/18, 10:06 AM
This Pointer - Object Oriented Programming Que... about:reader?url=https://www.sanfoundry.com/...

class to mention to which class does the object belong to.


And *const this denotes that the this pointer is having a
constant value.

Sanfoundry Global Education & Learning Series –


Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming


(OOPs), here is complete set of 1000+ Multiple Choice
Questions and Answers.

8 of 8 3/19/18, 10:06 AM

You might also like