call by value program in c
C programming Tutorials

Call by Value Program in C

Call by Value Program in C

  • Call by Value Program in C is a method of passing the arguments to function and call the function in main( ) method.
  • In tutorial we have discussed the concept of formal argument and actual argument.
  • We have explained the concept of call by value method with help of an example.
  • Call by value program in C is also executed with output.

Frequently Asked Questions

  • What is actual arguments in c ?
  • What is formal arguments in c ?
  • What is call by Value in C ?

What are actual arguments ?

Parameters or arguments that are passed to a function at the time of function calling inside the main() function of the program are known as actual arguments.

For example in the c program discussed in this tutorial a and b are the actual arguments.

What are formal arguments ?

Parameters or arguments that are passed to a function at the time of function definition are known as actual arguments.

For example in the c program discussed in this tutorial x and y are the actual arguments.

What  is call by Value method ?

In call by value method the value of actual arguments does not change if we change the value of formal parameters.

C Program for Call Value method is given below

#include <stdio.h>

void swap(int x , int y);  // function declaration

int main()
{

int a = 10;
int b = 20;

printf(“Before swapping the values in main a = %d, b = %d\n”,a,b);

swap(a,b);  // function calling

parameters in call by value, a = 10, b = 20

printf(“After swapping values in main a = %d, b = %d\n”,a,b);

}
void swap (int x, int y)
{

printf(“before swapping value of x =%d and y = %d\n”,x,y);

int temp;

temp = x;

x=y;

y=temp;

printf(“After swapping value of x =%d and y = %d\n”,x,y);

}

Output

When we will execute above call by value program in c then following output will be generated.

call by value method in c

When we execute the above call by value program then in the output we found that by changing the value of formal arguments x and y the value of actual arguments a and b does not change value of actual argument a and b remain same after swapping.

Conclusion and Summary

  • In this tutorial we have explained the concept of actual arguments and formal arguments in c.
  • Call by value program in c is also explained in this tutorial.

Next Tutorial – Call by Reference Program in C

Leave a Reply

Your email address will not be published. Required fields are marked *