C program to swap two values by Call by reference || call by reference || Pointers || C Programming
In this, we are going to swap values using call by reference by using Pointers in C Programming Language.


 
#include <stdio.h>
void swap(int *, int *); /*function prototype*/

int main()
{
    int x, y;
    scanf("%d %d", &x, &y);
    printf("Before Swapping:x=%d y=%d\n", x, y);
    swap(&x, &y); /*function call*/
    printf("After Swapping:x=%d y=%d", x, y);

    return 0;
}

void swap(int *a, int *b) /*function definition*/
{
    int temp;
    temp = *a; /*assign the value at address a to temp*/
    *b = *a;   /*put b into a*/
    *a = temp; /*put temp into b*/
}

//..........Coded by Ananya Maurya

#ENJOY CODING


Post a Comment

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

Previous Post Next Post