Q:

C program to add two numbers using pointers

0

C program to add two numbers using pointers

 

C program for the addition of two numbers using pointers. In the program, we have two integer variables x and y and two pointer variables p and q. We assign the addresses of x and y to p and q respectively and then assign the sum of x and y to the variable sum. Remember '&' is the address of operator and '*' is value at the address operator.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include 
int main()
{
   int first, second, *p, *q, sum;

   printf("Enter two integers to add\n");
   scanf("%d%d", &first, &second);

   p = &first;
   q = &second;

   sum = *p + *q;

   printf("Sum of the numbers = %d\n", sum);

   return 0;
}

output:

Enter two integers to add

3

4

Sum of the numbers = 7

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now