Swap two numbers by using function in C Programming


Swap two numbers by using function in C Programming

Image result for Swap two numbers by using function

int main (void)
{
int a = 10;
int b = 20;

printf("current value of a: %d\n", a);
printf("current value of b: %d\n" b);
//call function func1 to swap the values
Func1(&a,&b);
return 0;
}

voud func1(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
printf("value of a: %d\n", *a);
printf("value of b: %d", *b);
}

Pointer is essential in C programming. Take note I used pointer to swap the values in function func1.

No comments