Test Series - oops

Test Number 67/78

Q: Which is the pointer which denotes the object calling the member function?
A. Variable pointer
B. This pointer
C. Null pointer
D. Zero pointer
Solution: 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.
Q: 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 called
Solution: 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.
Q: Which among the following is/are type(s) of this pointer?
A. const
B. volatile
C. const or volatile
D. int
Solution: 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.
Q: 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 itself
Solution: 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.
Q: 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)
Solution: 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.
Q: 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
Solution: 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.
Q: 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 function
Solution: 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.
Q: The this pointers _____________________
A. Are modifiable
B. Can be assigned any value
C. Are made variables
D. Are non-modifiable
Solution: 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.
Q: 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
Solution: 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.
Q: 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
Solution: 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.

You Have Score    /10