C Program - Addition using pointers
#include <stdio.h>
#include <conio.h>
int main()
{
int first, second, *p, *q, sum;
printf("Enter two integers to add\n");
scanf("%d%d", &first, &second);
p = &first;
/*storing address of first in p*/
q = &second;
/*storing address of second in q*/
sum = *p + *q;
/*adding contents of address stored in p & q*/
printf("Sum of entered numbers = %d\n",sum);
getch();
return 0;
}
#include <conio.h>
int main()
{
int first, second, *p, *q, sum;
printf("Enter two integers to add\n");
scanf("%d%d", &first, &second);
p = &first;
/*storing address of first in p*/
q = &second;
/*storing address of second in q*/
sum = *p + *q;
/*adding contents of address stored in p & q*/
printf("Sum of entered numbers = %d\n",sum);
getch();
return 0;
}
Output
-------------
Comments
Post a Comment