Call by Value

Call by value in C is where in the arguments we pass value and that value can be used in function for performing the operation. Values passed in the function are stored in temporary memory so the changes performed in the function don’t affect the actual value of the variable passed.

Example:

C




// C Program to implement
// Call by value
#include <stdio.h>
  
// Call by value
int sum(int x, int y)
{
    int c;
    c = x + y;
  
    // Integer value retured
    return c;
}
  
// Driver Code
int main()
{
    // Integer Declared
    int a = 3, b = 2;
  
    // Function Called
    int c = sum(a, b);
    printf("Sum of %d and %d : %d", a, b, c);
  
    return 0;
}


Output

Sum of 3 and 2 : 5

C Function Arguments and Function Return Values

Prerequisite: Functions in C

A function in C can be called either with arguments or without arguments. These functions may or may not return values to the calling functions. All C functions can be called either with arguments or without arguments in a C program. Also, they may or may not return any values. Hence the function prototype of a function in C is as below: 

Similar Reads

Call by Value

Call by value in C is where in the arguments we pass value and that value can be used in function for performing the operation. Values passed in the function are stored in temporary memory so the changes performed in the function don’t affect the actual value of the variable passed....

Call by Reference

...

Types of Function According to Arguments and Return Value

Call by reference is the method in C where we call the function with the passing address as arguments. We pass the address of the memory blocks which can be further stored in a pointer variable that can be used in the function. Now, changes performed in the values inside the function can be directly reflected in the main memory....

Contact Us