Tuesday, May 17, 2011

5.2 Pointers and Function Arguments

  • Since C passes arguments to functions by value, there is no direct way for the called function to alter a variable in the calling function
  • Because of call-by-value, function below only swaps copies of a and b:














  • The way to obtain the desired effect is for calling program to pass pointers to the value to be changed:



















  • Pointer arguments enable a function to access and change objects in the function that called it


No comments:

Post a Comment