Write a program to SWAP two numbers in C Language - Program to Swap two numbers using pointers

Program to Swap two numbers using pointers in C

#include<stdio.h>

int main()

{

    int a, b;

    int *swapa, *swapb;

    int temp;

    printf("Enter First Number here = ");

    scanf("%d", &a);

    printf("\nEnter Second Number here = ");

    scanf("%d", &b);

    swapa = &a;

    swapb = &b;

    temp = *swapa;

    *swapa = *swapb;

    *swapb = temp;

    printf("\nThe values after swapping are: a = %d b = %d\n", a, b);

    return 0;

}

इस कोड को हमने CODEBLOCK पर बना कर run किया है

OUTPUT

Comments