Examples of Pointers (cont)
In C, parameters are "call-by-value"
- changes made to the value of a parameter do not affect the original
- function
swap() tries to swap the values of a and b , but fails because it only swaps the copies, not the "real" variables in main()
We can achieve "simulated call-by-reference" by passing pointers as parameters
- this allows the function to change the "actual" value of the variables
|