Monday, November 17, 2014

3.2.4 PASSING VALUES TO FUNCTIONS


Call by Value

§  In this method, the value of each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function.

§  The changes made to the formal arguments in the called function have no effect on the values of actual arguments in the calling function.

 

Example program:

#include<stdio.h>

void swapv ( int x, int y);

void main( )

{

            int a  = 10, b = 20;

            swapv ( a, b);

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

}

void swapv ( 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 = 10, b = 20

 

No comments:

Post a Comment

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