C Program to Swap Two Numbers Using Pointers

If you want to know about “C Program to Swap Two Numbers Using Pointers” then refer to this article. Let’s go for an article to do this task below.

C Program to Swap Two Numbers Using Pointers

C Program to Swap Two Numbers Using Pointers

Program Code

#include <stdio.h>
int main()
{
   int x, y, *a, *b, temp;

   printf("Enter the value of x and yn");
   scanf("%d%d", &x, &y);

   printf("Before Swappingnx = %dny = %dn", x, y);
   
   a = &x;
   b = &y;
   
   temp = *b;
   *b   = *a;
   *a   = temp;

   printf("After Swappingnx = %dny = %dn", x, y);
   
   return 0;
}

Final Thoughts

I hope this article helps you to know about “C Program to Swap Two Numbers Using Pointers“. We will post new C/C++ project tutorials as soon as possible so stay tuned with us. Don’t forget to bookmark us.

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