Hello, this is a problem from a written homework assignment:
i have to draw out a stack model for this
Code:
void foo(int **i, int **j){
int *temp;
if (**i < **j) {
temp = *i;
*i = *j;
*j = temp;
}
}
int main() {
int a = 3;
int b = 4;
int *x, *y;
x = &a;
y = &b;
foo(&x, &y);
printf("a = %d\n", a);
printf("b = %d\n", b);
printf("*x = %d\n", *x);
printf("*y = %d\n", *y);
As a hint, he gave us the output:
--output--
a=3
b=4
*x = 4
*y = 3
I have a = 3, b = 4 and x points to a(3) and y points to b(4). however, when foo is called, i dont understand the double pointers. Somehow, judging by the output, the x and y pointers are switched using i and j. any help would be appreicated