C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 35)
35.
Which of the following ways are legal to access a class data member using this pointer?
this->x
this.x
*this.x
*this-x
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
12 comments Page 1 of 2.

Ranjit said:   1 decade ago
Hello @Vandana.

The This is a pointer which points to the current object (Through which the function or data member is being called. ).

To access any of the members of the class, we need a object or a pointer to the object.

So you can use This.x.

But when you are treating This as a pointer you should go with This->x.

Sai said:   1 decade ago
The most common reason for using the this keyword is because a field is shadowed by a method or constructor parameter.

Harsh said:   1 month ago
-> operator is used for accessing the pointer type.

But *this.x can also be used as we are de-refencing it?

Ranjit said:   1 decade ago
But This.x is not allowed in C++ as This is a pointer to the Current object.

It is allowed in C#.

Sagar H Y said:   2 years ago
We have used the arrow operator (- >) for access the class data members using pointer.

Garg said:   4 years ago
This pointer contains the address of the object in which we are using this pointer.

Rahul chaudhary said:   1 decade ago
What is the legal way to access class data member using this pointer in Java?

Anoimee said:   7 years ago
What is this pointer? Please explain me.

Hruturaj Nikam said:   1 decade ago
(*this).x is equivalent to this->x.
(1)

ASSIA said:   4 years ago
Please can you hive me an exemple


Post your comments here:

Your comments will be displayed after verification.