this Pointer in C++

‘this’ is a reserved keyword in c++. It is used to get the variables or member functions present in the current class. ‘this’ pointer is not available for the friend functions because they are not members of class.

It is given as an implicit argument to the member functions.

Let’s see the code below to understand more about this pointer.

Output:

The name of person is Lucy

Age of Lucy is: 25

Salary of Lucy is: 25000

Address of Lucy is: 35 B Wall Street

So whenever we write ‘this’ pointer it implies that the variable or member function is from the current class in which the code is running.

Leave a Comment

Your email address will not be published.