Skip to content
Home » C Program to add Two Number Using Pointer

C Program to add Two Number Using Pointer

Learn about C Program to add Two Number Using Pointer in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C Program to add Two Number Using Pointer

The variables taking two numbers is assigned to pointer pa,pb .so that further calculations are calculated and store in another variable pointed by pointer pc.

#include<stdio.h>
int main()
{
  int a, b, c;
  
  int *pa, *pb, *pc;
  pa=&a, pb=&b, pc=&c;
  printf("Enter two number: ");
  scanf("%d %d", pa, pb); 
  // pa and pb have address of a & b respectively
  *pc = *pa + *pb;
  printf("Sum=%d\n",*pc);
  return 0;
}

Output:

Enter two number: 56 72
Sum=128

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Sort Strings in Lexicographical Order in C
C Program to Search a String in the List of Strings