C program to implement call by value and call by reference

This C program implements the types of function calls in C, the call by value and call by reference.

This example tries to explain how call by value and call by reference work in C.


Topic: Actual and formal parameters in C programming

The parameters inside the function declaration or definition are the formal parameters, and the parameters passed to the function during function call are the actual parameters.

In the example below, a is actual parameter and b is the formal parameter.


Topic: Difference between call by value and call by reference in C

In call by value, a copy of the actual parameters is passed to the function and the changes made in the formal parameters are not reflected back to the actual parameters. In call by reference, the actual parameter(memory address) itself is passed to the function and the changes made in the formal parameters are reflected back to the actual parameters.

This means, in call by value method, the memory address of actual and formal parameters will be different and in call by reference method, the memory address of actual and formal parameters will be the same.

Reflecting back means if you add 10 to the formal parameters, then the value of the actual parameter will also increase by 10.


Program: Implement call by value and call by reference in C


Output: Print values after function calls

Enter the value of a: 71

After calling by value, a= 71
After calling by reference, a= 81

Share your code and queries in the comments.

Share this programming article with your programmer friends.

Follow us on twitter.

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

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