-->




C plus plus assignment help service

c++ pointer addition example

Leave a Comment
Write a program which calculates addition of two numbers using pointers. program has three functions which receives two pointers reference. Three functions returns int, float and double sum of numbers. This c++ tutorial use the following concepts.


  • pointers in c++
  • functions
  • passing reference to function

This code has been tested on codeblocks c++ compiler

C++ source code
#include <iostream>
using namespace std;

int Sum(int *, int *);
float Sum1(int *,int *);
double Sum2(int *, int *);


int main()

{
    int a,b;


 cout<<"Enter 1st Value:";
 cin>>a;

 cout<<"Enter 2nd Value:";
 cin>>b;

    cout<<"...............ADDITION.............." <<endl <<endl;

 cout<<"The integer sum of these numbers is:"<<Sum(&a,&b)<<endl;
 cout<<"The float sum of these numbers is:"<<Sum1(&a,&b)<<endl;
 cout<<"The double sum of these numbers is:"<<Sum2(&a,&b)<<endl;

 cout<<endl <<endl;

 cout<<endl <<endl;


 return 0;

}


int Sum(int *x, int *y )

{
 int sum;
 sum=(*x + *y);
 return sum;
}

float Sum1(int *x,int *y )

{
 float sum;
 sum=(*x + *y);
 return sum;
}

double Sum2(int *x, int *y )
{
 double sum;
 sum=(*x + *y);
 return sum;

}



Input output of code
c++ pointer example to add two numbers

addition functions
two number additions using pointers c++
Find more here: c++ examples with output
github source

0 comments:

Post a Comment