We called the function foo(&x, &y)
in the main
function but then why did we call swap (x, y)
inside void foo
function as swap (&x, &y)
?
#include <stdio.h>
#include <stdlib.h>
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void foo(int*p1, int*p2) {
*p1 += *p2;
swap(p1, p2);
*p2 *= *p1;
}
int main(){
int x = 5, y = 9;
foo(&x, &y);
printf("x=%d\n", x);
printf("y=%d\n", y);
system("PAUSE");
return 0;
}