C Program to Add Two Numbers Using Pointers and Call by Reference Full Project For Beginners

  • Post author:
  • Post category:c++
  • Post comments:0 Comments

 

 

pointersadd.c

 

 

#include <stdio.h>
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;
}

 

 

Call by Reference`

 

 

#include <stdio.h>
long add(long *, long *);
 
int main()
{
   long first, second, *p, *q, sum;
 
   printf("Input two integers to add\n");
   scanf("%ld%ld", &first, &second);
 
   sum = add(&first, &second);
 
   printf("(%ld) + (%ld) = (%ld)\n", first, second, sum);
 
   return 0;
}

long add(long *x, long *y) {
   long sum;
   
   sum = *x + *y;
   
   return sum;
}

Leave a Reply