In this code example the swap function does not work as intended since it swaps two variables that exist only inside the scope of that function. The function allocates space on the stack and performs the swap within the scope of the function. However, the swap is promptly forgotten once the function is complete and the space on the stack is freed without updating the global variables.
To solve this, simply declare the parameters as pointers to the global variables:
In the second code example you were able to change the values of the variables only because you were constantly de-referencing a pointer within the function instead of trying to change the values directly
In another example, suppose you want to modify the values of 2-3 variables during a function call. Since C does not allows us to return multiple values, a clever way to get around this is to pass the pointers to the variables to that functions, and make changes to their value inside that function.