Passing Function Arguments in C : Call By Value

In C language, there are two ways that parameters/arguments can be passed  to a Function :
  • Call By Value
  • Call By Reference 

Call By Value :

In this method of calling a function, the value of arguments are copied to the formal parameter of the function, so in this case the changes made to the parameter have no effect on the argument.
By default C uses call by value to pass the arguments to the function. In general this means that code within a function cannot alter the arguments used to call the function. Consider the below C program:
#include <stdio.h>

int sqrd(int n);

int main() {
  int num = 6;
  printf("Squred of %d : %d\n", num, sqrd(num));
  return 0;

int sqrd(int n) {
  n = n*n;
  return n;
Output :

Squred of 6 : 36

In the above example, the value of the argument to sqrd(), which is num = 6, is copied into the parameter n. And when the assignment n = n*n takes place, only the local variable n is modified. The variable num, which used to call sqrd(), still has the value 6. Hence the output is 36.  At here, remember that it is a copy of the value of the argument that is passed into the function, and what occurs inside the function has no effect on the variable used in the call.

Next Topic :