// 24T3 COMP1511 Week 5 Lecture 2 // variables/data are passed into functions by value // a copy of the value gets passed into the function // Here we pass in the addresses of the variables // so we can go directly to their address and modify // them from within the function #include void update(int *x, int *y); // TO DO FIX SWAP void swap(int *x, int *y); int main(void) { int x = 2; int y = 5; printf("%d %d\n", x, y); // Pass in the addresses of x and y // So update can use the addresses to // go modify x and y update(&x, &y); printf("%d %d\n", x, y); //TODO FIX THIS swap(&x, &y); printf("%d %d\n", x, y); return 0; } // This function uses pointers. // We can dereference x and y and modify the data // at the given addresses void update(int *x, int *y) { *x = *x + 1; *y = *y - 1; } // This function will only modify the local copy of x and y // TODO FIX void swap(int *x, int *y) { int tmp = *x; *x = *y; *y = tmp; }