Pass by Pointer

Similar to the pass by reference method of passing actual values to a function, this method uses pointers (akin to the C method) to act upon the actual data being passed in.

 

In this case, the address of the variable is sent by the caller to the function, which accepts the incoming parameters as pointers. The pointers are then used within the function:

 

Compile & Run:

a and b in main before swap: 17, 42
x and y in myFunc: 42, 17
a and b in main: 42, 17

Leave a Reply