Pages

Tuesday, May 2, 2017

Use of Pointer to add two numbers.


#include <stdio.h>
int main()
{
   int num1, num2, *ptr_num1, *ptr_num2, total;

   printf("Enter two numbers:");
   scanf("%d%d", &num1, &num2);
   
//Initialize pointers with memory addresses of num1 and num2

   ptr_num1 = &num1;
   ptr_num2 = &num2;

   total = *ptr_num1 + *ptr_num2;

   printf("Addition of two numbers = %d.",total);
   return 0;
}

Output of program

Enter two numbers:10 20
Addition of two numbers = 30.


No comments:

Post a Comment