In this article, we will discuss the concept of the C++ Example to subtract two integer using pointer in C++ programming language
In this post, we are going to learn how to write a program to find the subtraction of two numbers using pointer in C++ programming language
The program use to calculate subtraction of given two integer numbers using pointer in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; int main() { int num1,num2; //1 declare variable int *ptr1,*ptr2; //2 declare pointer variable int sub; //3 num1=3150; //4 variable initiakization num2=570; ptr1=&num1; ptr2=&num2; //5 assign the address of the variable to pointer variable sub=*ptr1 - *ptr2; //6 //calculate subtraction cout<<"Subtraction of the given two integer values is: "<<sub; //7 //find the output and display on the screen getch(); return 0; }
When the above code is executed, it produces the following result
Subtraction of the given two integer values is:2580
The program allow the user to enter two numbers and then calculates subtraction of given two integer numbers without using pointer in C++ language
Program 2
#include <iostream> #include <conio.h> using namespace std; int main() { int num1,num2; //1 int *ptr1,*ptr2; //2 int sub; //3 cout<<"Please enter value for num1: "; //4 cin>>num1; //5 cout<<"Please enter value for num2: "; //4 cin>>num2; //7 ptr1=&num1; //8 ptr2=&num2; sub=*ptr1 - *ptr2; //10 cout<<"Product of the two integer values is: "<<sub; //11 getch(); return 0; }
When the above code is executed, it produces the following result
Please enter value for num1:2000 Please enter value for num2: 500 Subtraction of the given two integer values is: 1500
Methods
Similar post
C program find the sum of two numbers using the function
C program find the sum of two numbers using recursion
C program to find the product of two numbers using the pointer
C++ program find the sum of two numbers using the function
C++ program find the sum of two numbers using recursion
C++ program to find the product of two numbers using the pointer
Suggested for you
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…