Difference Between Call By Value And Call By Reference in C msbte | Advantages of Function in C msbte

Difference Between Call By Value And Call By Reference in C msbte | Advantages of Function in C msbte

Difference Between Call By Value And Call By Reference in C msbte | Advantages of Function in C msbte
Difference Between Call By Value And Call By Reference in C msbte | Advantages of Function in C msbte


Call By Value vs Call By Reference

Parameters
Call By Value
Call by Reference
Definition
The method of calling a function by passing actual values of parameters is called as call by value.

The method of calling a function by passing address (location numbers) of parameters is called as call by reference.

Syntax Function declaration
Syntax of function header in definition:
return_type function_name (type1 argument1, type2 argument2,…);
Syntax of function header in definition:
return_type function_name (type1 *argument1, type2 *argument2,…);
Syntax function call
Syntax function call:
function_name (argument1, argument2, ….)
Syntax function call:
function_name (&argument1, &argument2, ….)
Complexity
If program is large then there may be possibility conflicting or interchanging the values while calling the function by using call by value
Even though the program is large of ,no confusion will or occur during calling of the function by using call by reference
Modifications
Inside the function definition if any changes are done with the value of parameter which was passed to it;it will not affect the actual parameter.
As while calling function, pointer the location where the data is stored is passed to the function so the all modifications are done directly to that location therefore all modification reflects on the actual parameter.
Efficiency
The Call by value functions are less efficient than call by reference functions.
The Call by reference functions are more efficient than call by value functions.


Advantages of Function

  • Instead of writing all the code in main () function itself it is easy to combine code into small functions according to their functionalities.
  • As the huge code is divided into functions it is easy to read, debug, test, maintain, and modify the function individually.
  • Top down manner is followed while calling the functions first main() function Step and then according to the order in which functions are called execution is done 
  • Code re-usability is achieved by defining the function.Any number of times the block of code with different values can be called.
  • Also length of program gets reduce as function defined only once and later whenever require can be called any number of times.
  • C allows us to use library functions and also allows extending the standard library functions by adding user defined functions into C library. So that the functions can be used by other programs.

Post a Comment

Previous Post Next Post