C – Call by Value and Call by Reference with Example2 min read

There are two ways in which the argument can be passed through a function in C Programming.

  1. Call by Value
  2. Call by Reference

Call by Value in C.

In this method, the actual argument is copied to the formal parameter of the function. Hence any operation performed on the argument does not affect the actual parameters. By default, C programming uses call by value to pass arguments.

Since the actual parameter is copied to formal parameters, different memory is allocated for both parameters.

Example: Swap the values of two variables in C Programming:

The output of call by Value:


Call by Reference.

Unlike call by value method, here the address of the actual parameter is passed to a formal parameter rather than value. Hence any operation performed on formal parameters affects the value of actual parameters.

The memory allocation for both actual and formal parameters are same in this method.

Example: Swap the values of two variables in C Programming:

The output of call by Reference:


MORE

Keith Number Program in C

In this tutorial, we will write a Keith number in C. It is one of the most asked questions in an interview. Before that, you …
Read More

Keith Number Program in C++

In this tutorial, we will write a Keith number in C++. It is one of the most asked questions in an interview. Before that, you …
Read More

Singly linked list Program C++

In this tutorial, we will write a C++ program to implement singly linked list. In this program, we will create a separate function for each …
Read More

Fascinating Number Program in C

In this tutorial, we will write a C program to check whether the given number is a Fascinating number or not. You may go through …
Read More

Peterson Number in C

In this tutorial, we will learn about the Peterson number and check if the number is Peterson or not in C. What is Peterson Number? …
Read More

Peterson Number in C++

In this tutorial, we will learn about the Peterson number and write a C++ program to check if the given number is a Peterson number …
Read More