Programming in C++ using pointer

program 1:
#include<iostream>
using namespace std;
class pointer{
float a,b;
public:
float setnumber(int n,int n1){
a=n;
b=n1;

}
void display(){
cout<<a<<endl;
cout<<b<<endl;
}
};
int main(){
pointer p;
pointer *p1;
pointer **p2;
p1=&p;
p2=&p1;
p1->setnumber(12,54);
p1->display();
return 0;

}

Program 2:

#include<iostream>
using namespace std;
void add(int *a,int *b)
{
int sum=0;
sum=*a+*b;
cout <<"sum "<<sum;
}
int main()
{
int x,y;
cout<<"Enter value of x  and y";
cin>>x>>y;
int *q,*w;
add(&x,&y);
}

No comments:

Post a Comment