Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

21 Jul 2012

C Program to add two numbers / Integers using Pointers

C Program to add two numbers / Integers using Pointers :

PROGRAM: 


#include<stdio.h>
#include<conio.h>
main()
{

   int num1,num2, *p, *q, sum;
   /* *p,*q are integer pointer variables*/
   printf("\n Enter two integers to add: ");
   scanf("%d %d", &num1, &num2);

   p = &num1;   /* &num1 gives the value at address of num1*/
   q = &num2;

   sum = *p + *q;  /* adding the values of two pointer variables*/

   printf("\n Sum of entered numbers is: %d",sum);  /*printing sum*/
   getch();

   return 0;
}

Sample Output: ( using GNU GCC Compiler with Code Blocks IDE )

Enter two integers to add: 15 10
Sum of the entered numbers is: 25



No comments:

Post a Comment