Swapping using call by reference

Call by reference :

In Call by reference method, the function is called by sending reference (address) of the variable in the function call statement. All the changes are done directly in the memory of passed variable.

ALGORITHM:
In this algorithm, temp is used to store the value at address pointed by x temporarily.
x and y are the address pointers.

SWAP(*x,*y)

    1. SET temp=*x
    2. SET *x=*y
    3. SET *y=temp

C SOURCE CODE:

Leave a Reply

Your email address will not be published. Required fields are marked *