1 Answers
Code:
#include <iostream>
using namespace std;
class test
{
int a, b;
public:
void show()
{
a = 10;
b = 20;
cout<<“Object address = “<<this;
cout<<“\na =”<<this->a<<endl;
cout<<“b =” <<this->b;
}
};
int main()
{
test t;
t.show();
return 0;
}
Output:
Object address = 0x69fee8
a =10
b =20
Code 02:
#include <iostream>
using namespace std;
class test
{
int a, b;
public:
void show(int a, int b)
{
this->a=a; //(*this).a=a;
this->b=b; //(*this).b=b;
}
void disp()
{
cout<<a<<“\n”<<b<<endl;
}
};
int main()
{
test t;
t.show(10,20);
t.disp();
return 0;
}
Output:
10
20