In this article, we will discuss the concept of the 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 <stdio.h> #include <stdlib.h> int main() { int num1,num2; //declare variables num1,num2 int *ptr1,*ptr2; //declare pointer variable int sub; num1=350; //variable initialization num2=50; ptr1=&num1; //assign the address of the variable to pointer variable ptr2=&num2; sub=*ptr1 - *ptr2; //calculate the subtraction using pointer printf("Subtraction of the given two integer values is: %d",sub); //display result 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: 300
The program allow the user to enter two numbers and then calculates subtraction of given two integer numbers using pointer in C language
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int num1,num2; //1 int *ptr1,*ptr2; //2 int sub; //3 printf("Please enter value for num1: "); //4 scanf("%d",&num1); //5 printf("Please enter value for num2: "); //6 scanf("%d",&num2); //7 ptr1=&num1; //8 ptr2=&num2; sub=*ptr1 - *ptr2; //10 printf("Subtraction of the two integer values is: %d",mul); //11 getch(); return 0; }
When the above code is executed, it produces the following result
Please enter value for num1: 1000 Please enter value for num1: 700 Subtraction of the two integer values is: 300
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
Suggested for you
Input-output function in C language
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…