Tuesday 24 July 2012

swap values of two variables using call by reference comments

How to write C Program to swap values of two variables using call by reference
#include


//function to swap values

void swap(int *a,int *b)

{

int temp;

temp=*a;

*a=*b;

*b=temp;


printf("\nValues of a and b within the function: %d %d",*a,*b);


}


int main()

{

int a,b;


//Accept value of a & b

printf("\nEnter value of a:");

scanf("%d",&a);

printf("\nEnter value of b:");

scanf("%d",&b);


//print values before calling swap function

printf("\nValues of a and b before calling the function: %d %d",a,b);


//Calling swap function

swap(&a,&b);


//print values after calling the swap function

printf("\nValues of a and b after calling the function: %d %d",a,b);


}
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: