C Program to Add Two Numbers Using Pointers and Call by Reference

Hello reader, If you are looking to know the concept “C Program to Add Two Numbers Using Pointers and Call by Reference” then read this article to learn about it clearly. Move on to the article directly.

C Program to Add Two Numbers Using Pointers and Call by Reference

C Program to Add Two Numbers Using Pointers and Call by Reference

Source Code

#include <stdio.h>
int main()
{
   int first, second, *p, *q, sum;

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

   p = &first;
   q = &second;

   sum = *p + *q;

   printf("Sum of the numbers = %dn", sum);

   return 0;
}
#include <stdio.h>
long add(long *, long *);
 
int main()
{
   long first, second, *p, *q, sum;
 
   printf("Input two integers to addn");
   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;
}

Final Thoughts

I hope this article helps you to know about “C Program to Add Two Numbers Using Pointers and Call by Reference“. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment