Monday, November 17, 2014

5.1.2 CALL BY REFERENCE


§  In this method, the addresses of actual arguments in the calling function are copied into the formal arguments of the called function.

§  This means that, using these addresses, we would have an access to the actual arguments and hence we would be able to manipulate them.

 

Example program:

#include<stdio.h>

void swapr ( int *x, int *y);

void main( )

{

            int a  = 10, b = 20;

            swapr (& a, &b);

            printf( “a = %d, b = %d”, a, b);

}

void swapr ( int *x , int *y)

{

            int t;

            t = *x;

            *x = *y;

            *y = t;

            printf( “x = %d, y = %d”, x, y);

}

 

OUTPUT

x = 20, y = 10

a = 20, b = 10

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.