C Program Code for Swapping of numbers using Pointers

Program code:

#include<stdio.h>
int main()
{
int x  , y , z , *a , *b , *c  ;
printf("Enter value of x : ");
scanf("%d",&x);
printf("Enter value of y : ");
scanf("%d",&y);
printf("Before swapping x :  %d",x);
printf("\nBefore swapping y :  %d",y);
a = &x;
    b = &y;
c = &z;
*c = *a;
*a = *b;
*b = *c;
printf("\nAfter swapping x :  %d",x);
printf("\nAfter swapping y :  %d",y);
return 0;
}

Output:

.exe file

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.