On Dec 21, 2007 6:55 AM, p.angel88 <[EMAIL PROTECTED]> wrote:
> hi to all
> follows a program for call by value
> *********************************************************************
> #include<stdio.h>
> #include<conio.h>
> void swap(int,int);
void swap(int*, int*)
> void main()
> {
> int a,b;
> clrscr();
> printf("enter two values");
> scanf("%d%d",&a,&b);
> printf("value before swapping a=%d & b=&d",a,b);
> swap(a,b);
swap(&a, &b);
> printf("value after swapping a=%d & b=%d",a,b);
> getch();
> }
> void swap(int x,int y)
> {
> int t;
> t=x;
> x=y;
> y=t;
> }
void swap(int* x,int* y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
> ********************************************************************
> swapping is interchange of value
> if we assign a=5 & b=2 the output should be a=2 & b=5.
> but the output is coming same as input. so what is the mistake in
> program?
You were modifying copies of a and b, not the original a&b's.
--
PJH
"Statistics are like a bikini. What they reveal is suggestive, but
what they conceal is vital"
-- Aaron Levenstein