Home » C++ programs » C++ Most popular & searched programs

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.

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

Here, we declared pointer variables using new operator, read more about it : new operator in C++






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.