Arguments passed to a function in 'call by value' form are like a one way 
street.  The values are presented to the function that you are calling but 
there is no way for the function to get modifications to those values back to 
the caller.  The function acts upon it's own private copy of those variables.

If you want to pass multiple values to a function and return changes to those 
values to the caller, you probably want to use 'call by reference'.

So do something like this:

Redefine the swap function:   void swap(int *x, int *y)

Within the swap function when referencing x, use:  *x
Within the swap function when referencing y, use:  *y

Within main, when calling swap, use:  swap(&x, &y)




[email protected] wrote:
> hi to all
> follows a program for call by value
> *********************************************************************
> #include<stdio.h>
> #include<conio.h>
> 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);
> 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;
> }
> ********************************************************************
> 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?
> 



To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/c-prog/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/c-prog/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to