Pass pointers as the function arguments in c; Through this tutorial, we will learn 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 output 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