C Program to add two numbers using pointers


In this program, You will learn how to add two numbers using pointers in c.


25 = 15 + 10

30 = 10 + 20

Example: How to add two numbers using pointers in c.

#include<stdio.h>

int main() {

   int x, y, sum;
   int *a, *b;

   printf("Enter two numbers:");
   scanf("%d%d", &x, &y);

   a = &x;
   b = &y;

   sum = (*a) + (*b);
   printf("Sum is:%d", sum);

   return 0;
}

Output:

Enter two numbers:20 30                                                                                                                
Sum is:50