Q:

C++ program to add two integer numbers using pointers

0

C++ program to add two integer numbers using pointers

In last two programs, we have discussed how to find addition of two integer numbers with a normal way and addition of two integer numbers using user defined function?

In this program, we are calculating addition/sum of two integer numbers using pointers, here we will declare three integer pointers two store two input numbers and to store addition of the numbers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to add two numbers using pointers in C++

#include <iostream>
using namespace std;

int main()
{
	int *pNum1=new int;
	int *pNum2=new int;
	int *pAdd=new int;
	
	//read numbers
	cout<<"Enter first number: ";
	cin>>(*pNum1);
	cout<<"Enter second number: ";
	cin>>(*pNum2);
	
	//calculate addition
	*pAdd=*pNum1+*pNum2;
	
	//print addition
	cout<<"Addition is: "<<*pAdd<<endl;
	
	return 0;
}

Output

Enter first number: 100 
Enter second number: 200
Addition is: 300

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now