Hi, everyone. I have here a code of a program that interchanges the values of two int variables, x and y, by using pointers:
The thing is: how are the values of x and y changed in the main function, if the funtion interchange() doesn't return anything? Is it because this one works with pointers that point to x and y, in such a way that these pointers are the "bridge" between the main() and the interchange() functions?
void interchange(int * u, int * v);
int x = 5, y = 10;
printf("Originally, x = %d and y = %d.\n", x, y);
interchange(&x, &y); //send addresses to function
printf("Now, x = %d and y = %d.\n", x, y);
void interchange(int * u , int * v)
temp = *u; //temp = x //temp gets value that u points to
*u = *v; //x = y
*v = temp; //y = temp
Thanks in advance!