Objective C Function call by reference - Objective C

How Function call by reference is used in Objective-C?

  • Passing of arguments to a function using call by reference method copies the address of an argument into the formal parameter.
  • The address is used to access the actual argument used in the call inside the function.
  • The changes made to the parameter affect the passed argument.
  • Argument pointers are passed to the functions to pass the value by reference.
  • To declare the function parameters as pointer types as in the following function swap(), which exchanges the values of the two integer variables pointed to by its arguments.

Call the function swap() by passing values by reference as shown in below example:

On compiling and executing the above program, the following result is produced:

The above output shows that change has reflected outside of the function where as call by value changes does not reflect outside of the function.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Objective C Topics