This Pointer In C ++
The this pointer holds the address
of current object, in simple words you can say that this pointer points to the current object of the
class.
Fig: This Pointer In C++ |
Syntax:
this->variable=value;
Program:
#include<iostream.h>
#include<conio.h>
class BCA
{
int a,b;
public:
void inputdata(int
x,int y)
{
this->a=x;
this->b=y;
}
void outputdata()
cout<<a;
cout<<b;
}
};
void main()
{
BCA p;
p.inputdata(20,30);
p.outputdata();
getch();
}
Output:
20 30
No comments:
Post a Comment