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

Search this Site

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



1 comment:

  1. YOU CAN GET A HUGE LIST OF C PROGRAMS ON www.vitedu.in with output and in downloadable format.... Have a Look at it...

    ReplyDelete

Thanks for your comments.
-Sameer