Computer Science, asked by deveshverma2268, 1 year ago

Why does “this” pointer used in C++?

Answers

Answered by cutiealeeza132
0
Hyy dear
Every object in C++ has access to its own address through an important pointer called this pointer. ... Therefore, inside a member function, this may beused to refer to the invoking object. Friend functions do not have a this pointer, because friends are not members of a class. Only member functions have a this pointer.
Hope it will help you..
Answered by SerenaBochenek
0

In C++ "this" pointer is used to store the address of the current object.

Explanation:

The word current object means to point the data member which is declared inside the member functions. It acts as the implicit parameter to the member functions. 

Syntax: -

//creating class

public class PQR

{

private:

           int a;

public:

          void fun(int b)

          {

                    //this pointer stores the address of the object and it //access"a"

                    this->a = b;

          }                      

}

//main fucntion

int main()

{

       //creating object

       PQR obj1;

       //calling the function

       obj1.fun(5);

}

Learn more:

Pointer to pointer:

https://brainly.in/question/8974543

Pointer and its working:

https://brainly.in/question/14002495

Similar questions