• admin@embedclogic.com

Function Call by value and Call by reference

Function calling

As I explained in the previous chapter about the different types of function calls.On the basis of input parameter passed into the Function, “Function calling with input parameters” again divided into two category –

— Function Call by value

— Function Call by reference

Every initialized variable has some address in memory to keep its data.In call by value function, we have to pass the variable name or its value while in the call by reference we have to send the address of variable as an input parameter.

Function Call by value

In function Call by value, Input parameters are variables or some constants.

How does function call by value works

— Function prototype must be declared before its calling.

— In function call by value operation not performs on real(num1,num2) data but on its copy(num1_copy,num2_copy).

–The main function is the entry and exit point for any program in C.so we can call any self-defined function from main but the pointer will return back to the immediate statement of calling function because the exit of the program exists only in the main function.(see the third number in above flow).

Function Call by reference(address)

In function Call by reference, Input parameters shall be the address of variables or constant in function calling.

To understand this topic you must be familiar with the pointer concept first.

How does function call by reference works

In function call by reference, Operation performs on real(num1,num2) data because input parameters are nothing but the address of the actual variable inside the calling function. So if we do any changes to that address, it means we are doing this with the original value.