Thursday, July 29, 2010

Call By Reference in C && Call by Values in C

Call By Reference program in C
/* Program for inerchanging two numbers demonstrating Call By Reference in C */

#include<>
#include<>

void swap(int *,int *);

void main()
{
int x,y;
x=15;y=20;
clrscr();
printf("x=%d,y=%d\n",x,y);
swap(&x,&y);
//printf("\n%x %x",&x,&y);
printf("\n after interchanging x=%d,y=%d\n",x,y);
getch();
}

void swap(int *u,int *v)
{
int temp;
temp=*u;
*u=*v;
*v=temp;

return;
}

Call by Values in C
/* Program on interchanging two numbers demonstrating Call By Values in C*/
#include< stdio.h>
#include< conio.h>
void main()
{
int x,y;
x=15;y=20;
clrscr();
printf("x=%d,y=%d\n",x,y);
swap(x,y);
printf("\n after interchanging x=%d,y=%d\n",x,y);
getch();
}
swap(int u,int v)
{
int temp;
temp=u;
u=v;
v=temp;
return;
}


--
http://www.venkatmails.blogspot.com/

Venkat Mails, Fun , Cool pictures, Fun messages, Sardar Jokes, Quotations Moral stories Fun stories

http://www.venkatmails.blogspot.com/

No comments:

Post a Comment