C Pass Pointers as the Function Arguments

In this tutorial, i am going to show you how to pass pointers as the function arguments in c.

C Pass Pointers as the Function Arguments

/* Pass Pointers to Functions in C Example  */
#include<stdio.h>
 
void Swap(int *x, int *y)
{
    int Temp;
    Temp = *x;
    *x = *y;
    *y = Temp;
}
int main()
{
    int a, b;
    
    printf ("Please Enter 2 Integer Values :  ");
    scanf("%d %d", &a, &b);
    
    printf("\nBefore Swapping  A = %d and B = %d", a, b);
    
    Swap(&a, &b);
    
    printf(" \nAfter Swapping   A = %d and B = %d \n", a, b);
}

The result of the above c program; is as follows:

Please Enter 2 Integer Values :  1 2
Before Swapping  A = 1 and B = 2 
After Swapping   A = 2 and B = 1 

More C Programming Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published.