Tuesday, September 9, 2008

Parameter passing method in C language

C supports evidently two styles of parameter passing, to name
1. Passing by value
2. Passing by address.
In passing by value whatever operations or actions takes place in the function on formal argument will not really reflect on the orginal or actual argument.

In the case of passing by address, what ever action we carry out in the function in the addresses which are passed will really take place on the actual arguments.

For example, the following version of function SWAP will not exchange the values of the actual arguments.
void SWAP(int x, int y)
{
int T=x;
x=y;
y=T;
}
Where as the following version of SWAP does the required thing.
void SWAP(int *x, int *y)
{
int T=*x;
*x=*y;
*y=T;
}

We have some useful material kept at www.ritchcenter.com Please go through.
Prof NB Venkateswarlu
RITCH CENTER
www.ritchcenter.com/elearn

No comments: