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++

using namespace std;

class Test {
   int x, y;

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

int main() {

   Test tt(10, 20);

   return 0;


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