Write a C program to swap two integer values using pointers

09 a]Write a C program to swap two integer values using pointers.

swapping two integer values using pointers

below example shows the before swap and after swap


// C program to swap two variables
#include <stdio.h>
  
int main()
{
    int x, y;
    printf("Enter Value of x ");
    scanf("%d", &x);
    printf("\nEnter Value of y ");
    scanf("%d", &y);
  
    int temp = x;
    x = y;
    y = temp;
  
    printf("\nAfter Swapping: x = %d, y = %d", x, y);
    return 0;
}
output:
 Enter Value of x=12

Enter Value of y=14

After Swapping: x = 14, y = 12 

Leave a Reply

Your email address will not be published. Required fields are marked *