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



2 comments:

  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
  2. Very informative article.Thank you author for posting this kind of article .



    http://www.wikitechy.com/view-article/pointers-in-c-example-with-explanation



    Both are really good,
    Cheers,
    Venkat

    ReplyDelete