0% found this document useful (0 votes)
3 views

c++ code

Uploaded by

yogo4555
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

c++ code

Uploaded by

yogo4555
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;


double add(double, double);
double sub(double, double);
double (*evaluate)(double, double);
void swap1(int, int);
void swap2(int&, int&);
void swap3(int*, int* );
int main()
{
/*int var1=5;
int* ptr1;
ptr1=&var1;
*ptr1=10;
cout<<var1<<endl;
cout<<&var1<<endl;
cout<<ptr1<<endl;
cout<<*ptr1<<endl;
cout<<&ptr1<<endl;
int* ptr2=new int;
*ptr2=15;
delete ptr2;
ptr2=&var1;
*ptr2=20;
cout<<var1<<endl;
int num;
cout<<"enter the size of an array"<<endl;
cin>>num;
int* ptr3=new int[num];
for(int i=0;i<num;i++)
{

cout<<"enter elt";
cin>>*(ptr3+i);
}
for(int i=0;i<num;i++)
{

cout<<(ptr3+i)<<"\t"<<*(ptr3+i)<<endl;
}
delete []ptr3;
*/
int a=5,b=8;
evaluate=&add;
cout<<"\n sum="<<evaluate(a,b)<<endl;
evaluate=&sub;
cout<<"\n Difference="<<evaluate(a,b)<<endl;
swap1(a,b);
cout<<"\na="<<a<<"\tb="<<b<<endl;
swap2(a,b);
cout<<"\na="<<a<<"\tb="<<b<<endl;
swap3(&a,&b);
cout<<"\na="<<a<<"\tb="<<b<<endl;
return 0;
}
double add(double x, double y)
{
return x+y;
}
double sub(double x, double y)
{
return x-y;
}
void swap1(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
}
void swap2(int &x, int &y)
{
int temp;
temp=x;
x=y;
y=temp;
}
void swap3(int* x, int* y )
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}

You might also like