Description

 

The call by value technique of passing arguments to a function copies the particular value of an argument into the formal parameter of the function. during this case, changes created to the parameter within the operate don't have any result on the argument.

In call by value the actual value cannot modified by the formal parameters.

In call by value different memory allocated to the formal parameter because formal parameter in the copy of the actual value.

Where the actual argument used in the function call whereas formal parameter used in the definition of the function.

Lets See the example...

#include<stdio.h>

void func(int x);

int main(){
    int n = 40;
    // Before calling the function the value of n
    printf("Before Calling the Function value of n : %d", n);
    func(n);
    printf("After Calling the Function value of n : %d", n);
    return 0;
}

void func(int x){
    // Inside the function print the value before perform some operation
    printf("Inside the function the value before perform operation : %d", x);

    // Perform some operation

    x = x + 30;   // value changed of x
    
    printf("Inside the function the value after perform operation : %d", x);
}    

/*

Before Calling the Function value of n : 40
Inside the function the value before perform operation : 40
Inside the function the value after perform operation : 70
After Calling the Function value of n : 40

*/

Now Let's another Example...

Swap to numbers using function.

#include<stdio.h>

void swap(int x, int y);

int main(){
    
    int n = 34;
    int m = 20;
    
    // Before Calling function the value of n and m
    printf("Before Calling the function the value of n = %d , m = %d", n, m);
    
    // Calling function
    swap(n, m);
    
    // After Calling function the value of n and m
    printf("\nAfter Calling the function the value of n = %d , m = %d", n, m);
    return 0;
}
void swap(int x, int y){
    // Before Swap the value of x and y 
    
    printf("\nInside the function Before Swapping the value of x = %d, y = %d", x, y);
    
    // Swapping 
    
    int temp = x;
    x = y;
    y = temp;
    
    // After swap the value of x and typedef
    
    printf("\nInside the function After Swapping the value of x = %d, y = %d", x, y);
}


/*

Before Calling the function the value of n = 34 , m = 20
Inside the function Before Swapping the value of x = 34, y = 20
Inside the function After Swapping the value of x = 20, y = 34
After Calling the function the value of n = 34 , m = 20

*/

 

Comments

Login is mandatory to comment Please login

Recommended Posts

Call by Reference in C programming language

When we call a function and pass the variable / parameter in the function, when passing the address of the actual arguments from the calling function, that's why it is called call by reference.

C program to replace vowels with special characters

Write a c program to replace vowels with special characters.

File Read in C | File Handling | How to Read File

Write a program to read the file in c File Handling. How to read file is the main topic of file handling.

Insertion and deletion in doubly linked list in C program

Insertion and Deletion in Doubly linked list in C programming langauge Data Structure. How to Implement insertion and deletion all operation.

C program to check eligible for vote

Write a program to check that person is eligible for voting or not.

Voting program in C language using switch case

Write a program to check that person is eligible for voting or not using switch case.