Swapping two values with help of pointer


 

#include <stdio.h>

 #include<conio.h>

int main()

{

   int x, y, *a, *b, temp;

 

   printf("Enter the value of x and y\n");

   scanf("%d%d", &x, &y);

 

   printf("Before Swapping\nx = %d\ny = %d\n", x, y);

 

   a = &x;

   b = &y;

 

   temp = *b;

   *b = *a;

   *a = temp;

 

   printf("After Swapping\nx = %d\ny = %d\n", x, y);

 

   return 0;

}


Output:-

Enter the value of x and y

3

4

Before Swapping

x = 3

y = 4

After Swapping

x = 4

y = 3

Comments

Popular posts from this blog

Check whether the no entered is Palindrome or not

Calculate Factorial of a given no with help of Recursion

Find max. and min. element in the integer array