Search

Tuesday, April 2, 2019

C program to swap two numbers using call by value

Posted By Manisha Gupta 

This C program is to swap two numbers using call by value.The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.In C programming, C by default uses call by value to pass arguments.

Logic

We are using a function called swap().This function basically swaps two numbers, how we normally take a temporary variable in C to swap 2 nos.


#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
printf("Manisha enter any numbers a&b");
scanf("%d%d",&a,&b);
swap(a,b);
printf("\n a=%d , b=%d",a,b);
getch ();
}
void swap(int x,int y)
{
int t;
t=x;
x=y;
y=t;
printf("\n x=%d y=%d",x,y);
}

Follow on Facebook

ManishaTech . 2017 Copyright. All rights reserved. Designed by Manisha Gupta | Manisha Gupta