Swapping two numbers in C by call by reference || Call by reference || C programming
In this, we are going to see a program in which it will swap 2 numbers using call by reference method in C programming Language.


//WAP to swap 2 numbers, using call by Reference

#include <stdio.h>

void swap(int *a, int *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
    printf("\nAfter Swapping values in function are a = %d , b = %d\n", *a, *b);
}

void main()
{
    int a, b;
    printf("Enter the two numbers: ");
    scanf("%d %d", &a, &b);

    printf("\nBefore Swapping values in function are a = %d , b = %d\n", a, b);

    swap(&a, &b);

    printf("\nAfter Swapping values in main are a = %d , b = %d\n", a, b);
}


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post