Parameters in C functions

Raheelanjum
2 min read4 days ago

A parameter is the symbolic name for "data" that goes into a function. There are two ways to pass parameters in C: pass by value and pass by reference.

Pass by Value

Pass by value means that a copy of the data is made and stored by way of the name of the parameter. Any changes to the parameter have NO effect on data in the calling function.

Pass by Reference

A reference parameter "refers" to the original data in the calling function. Thus any changes made to the parameter are ALSO MADE TO THE ORIGINAL variable.

There are two ways to make a pass by reference parameter:

ARRAYS

Arrays are always passed by reference in C. Any change made to the parameter containing the array will change the value of the original array.

The ampersand is used in the function prototype.

function ( & parameter_name )

To make a normal parameter into a pass-by-reference parameter, we use the "& param" notation. The ampersand (&) is the syntax to tell C that any changes made to the parameter also modify the original variable containing the data.

Pass by Value Example:

In C, the default is to pass by value. For example

--

--

Raheelanjum
Raheelanjum

Written by Raheelanjum

Highly skilled and experienced content writer dedicated to crafting compelling, informative content that resonates with diverse audiences. Expertise spans blog

Responses (16)