Best post on call by value in C – part 2

What is Call by value in C ?

In this type of function calling the actual value of an argument is passed to formal parameters of the function.
Once a function receives the value then it will start its operation, but this operation will never affect the argument.
Operation will be performed on values but it will not affect argument variables.
Argument value will remain unchanged even after the function’s execution.

Example of call by value in C

#include <stdio.h>

void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}

int main ()
{

int x = 5;
int y = 8;

printf("Value of x before swapping : %dn", x );
printf("Value of y before swapping : %dn", y );

swap(x,y);

printf("Value of x before swapping : %dn", x );
printf("Value of y before swapping : %dn", y );

return 0;
}

Output :

Value of a before swapping : 5
Value of b before swapping : 8
Value of a before swapping : 5
Value of b before swapping : 8

As we can see in the above output the function’s operation will not affect values of argument variables.

 

Click here to understand call by reference.

CHECKOUT OTHER RELATED TOPICS

CHECKOUT OTHER QUIZZES

PRACTICALS IN C PROGRAM

Programs to understand the basic data types and I/O.
Programs on Operators and Expressions.
Programs on decision statements.
Programs on looping.
Programs on arrays.
Programs on functions.
Programs on structures and unions.
Programs on pointers.
Programs on string manipulations.
Practice Programs
1 – C program for leap year, easy and simple code
2 – Best C program to find sum of all digits
3 – Best C program to check Palindrome Number
4 – Best C program to check prime number
5 – Best C program to print Fibonacci series
6 – Best C program to reverse a number
7 – Best C program to reverse an array
8 – Best C program to find average of array
9 – Best C program to find frequency of array element
10 – Best C program to sort array in ascending order
11 – Best C program to find factorial using recursion
12 – Best C program to find sum of all numbers in array
13 – Best C program to find largest element in array
14 – Best C program to swap two numbers without third variable
15 – C Program to check if a number is even or odd
16 – C program to find Simple interest
17 – Best C program to add two matrices
18 – Best C program to count vowels and consonants in a string
19 – Best C program to find LCM
20 – Best C program to find HCF
21 – Best C program to swap two numbers using pointers
22 – Best C program to add two numbers using pointers
23 – Best C program to print Multiplication Table
24 – Best C program to check Armstrong number
25 – Best C program to print half pyramid of star(*)
26 – Best C program to print half pyramid of numbers
27 – Best C program to print reverse half pyramid of star
28 – Best C program to print reverse half pyramid of number
More coming soon…
We are aiming to explain all concepts of C in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment