C++ Program using this pointer


In this program, You will learn how to implement this pointer in C++.


this->x = x

this->y = y


Example: How to implement this pointer in C++

Run it Now
#include<iostream>
using namespace std;

class Test {
   int x, y;
public:

   Test(int x, int y) {
       this->x = x;
       this->y = y;
   }
   void display() {
       cout << "The value of x is :" << x;
       cout << "\nThe value of y is :" << y;
   }
};

int main() {

   Test tt(10, 20);
   tt.display();

   return 0;
}

Output:

The value of x is :10
The value of y is :20