Simple Program for Add Two Numbers Using Pointer in C


Declaration Syntax

p1 = &var1;
p2 = &var2;

var = *p1 + *p2;

Simple Program for Add Two Numbers Using Pointer

/* Simple Program for Add Two Numbers Using Pointer in C*/
/* Print Pointer Address Program,C Pointer Examples */

#include<stdio.h>

int main() {
  int *p1, *p2;
  int num1, num2, sum;

  printf("Pointer Example Program : Add Two Numbers \n");

  printf("\nEnter Two Numbers for Sum : \n");
  scanf("%d %d", &num1, &num2);

  p1 = &num1;
  p2 = &num2;

  sum = *p1 + *p2;

  printf("Sum of Two Numbers : %d", sum);
  return 0;
}

Sample Output:

Pointer Example Program : Add Two Numbers

Enter Two Numbers for Sum :
10
15
Sum of Two Numbers : 25