Subtract Two Numbers using Pointers C Program

By | December 12, 2015

Let us learn how to subtract two numbers using pointers in C programming using user-defined functions with an output.

The C program for subtraction of two pointers makes use of the de-reference operator, also known as the asterisk (*). The user-defined function used here makes use of the call by reference approach.

What is a Pointer?

A pointer is a variable which can be used to store the memory address of another variable which is of the same data-type.

There are many other arithmetic operations that can be performed on pointers in C programming, and they’re enlisted below:

  • Increment
  • Decrement
  • Addition

Note: This program to subtract two integers using pointers in C programming is compiled with GNU GCC compiler with gEdit editor on Linux Ubuntu 14.10 operating system.

C Program To Subtract Two Numbers using Pointers and Functions

#include<stdio.h>

int subtract(int *x, int *y);

int main()
{
      int num1, num2, res;
      printf("\nFirst Number:\t");
      scanf("%d", &num1);
      printf("\nSecond Number:\t");
      scanf("%d", &num2);
      res = subtract(&num1, &num2);
      printf("Subtraction of Two Numbers: %d", res);
      printf("\n");
      return 0;
}

int subtract(int *x, int *y)
{
      int temp;
      temp = *x - *y;
      return temp;
}

Output

C Program To Subtract Two Numbers using Pointers

If you have any doubts about this C program to subtract two numbers using pointers, let us know about it in the comment section.

RECOMMENDED PROGRAMS
C Program For Addition of Two Numbers using Pointers
C Program For Addition Two Numbers without Arithmetic Operator
C Program For Division Two Numbers without Arithmetic Operator
C Program For Subtraction Two Numbers without Arithmetic Operator
C Program For Multiplication Two Numbers without Arithmetic Operator

Let's Discuss