#include<iostream>
using namespace std;
class pointer
{
int a , *ptr; // declaration of pointer variable
public:
void get();
void multiplication();
};
void pointer :: get()
{
cout<<"Enter a no :";
cin>>a;
cout<<"a :"<<a<<endl;
ptr = &a; // address of "a" is stored at "ptr"
}
void pointer :: multiplication()
{
*ptr = *ptr * 5;
cout<<"After multiplication, a : "<<a<<endl;
}
int main()
{
pointer p;
p.get();
p.multiplication();
return 0;
}
OUTPUT:
using namespace std;
class pointer
{
int a , *ptr; // declaration of pointer variable
public:
void get();
void multiplication();
};
void pointer :: get()
{
cout<<"Enter a no :";
cin>>a;
cout<<"a :"<<a<<endl;
ptr = &a; // address of "a" is stored at "ptr"
}
void pointer :: multiplication()
{
*ptr = *ptr * 5;
cout<<"After multiplication, a : "<<a<<endl;
}
int main()
{
pointer p;
p.get();
p.multiplication();
return 0;
}
OUTPUT:
No comments:
Post a Comment