Tuesday, 25 July 2017

C program for Swap using Function Call By Value

C program for Swap using Function Call By Value.

This C program swaps two Integers using Call By Value method where the values of the variables are sent to the New Variables and the Old Values are not Swapped.

What is a Function:

A Function is a collection of statements that collectively carry out a project. Every C application has as a minimum one characteristic, that's most important(), and all of the maximum trivial applications can define extra functions. You may divide up your code into separate capabilities.

What is Swap in C:

C application to swap two numbers. C application to change  numbers with and with out the usage of 1/3 variable, swapping in c the use of suggestions, functions (name by reference) and using bit-wise XOR operator, swapping means interchanging.

Call by value:

Inside the Call by value technique the real arguments are copied to the formal arguments, subsequently any operation done via function on arguments doesn’t have an effect on real parameters. It could sound complicated but allow me explain this with the help of an example:

Why values remain unchanged even after the swap?

The reason is same – function is called by value for num1 & num2. So actually var1 and var2 gets swapped (not num1 & num2). As in call by value actual parameters are just copied into the formal parameters.


int swap(int,int);
void main()
int i=10,j=20;
printf("Befor Swaping i=%d j=%d",i,j);
printf("\nAfter Swaping i=%d j=%d");
int swap(int i,int j)
int temp;
return temp;


Try it yourself.
If you have any problem you can tell me on comment box i will help you.

Viral Programs

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.