Void Swap (int x, int y);
Int main ()
{
Int a, b;
Printf (" do enter a, b: ");
Scanf_s (" % d % d ", & amp; A, & amp; B);
Printf (" Before swap: a=% d, b=% d \ n ", a, b);
Swap (a, b);
Printf (" After swap: a=% d, b=% d \ n ", a, b);
return 0;
}
Void Swap (int x, int y)
{
int temp;
temp=x;
X=y;
Y=temp;
}
Why can't enter the function carried out ah?
CodePudding user response:
The value of C language, need to pass the address just have effect, only supplies the reference:# include & lt; stdio.h>
Void Swap (int * x, int * y);
Int main (void)
{
Int a, b;
Printf (" do enter a, b: ");
Scanf_s (" % d % d ", & amp; A, & amp; B);
Printf (" Before swap: a=% d, b=% d \ n ", a, b);
Swap (& amp; A, & amp; B);
Printf (" After swap: a=% d, b=% d \ n ", a, b);
return 0;
}
Void Swap (int * x, int * y)
{
int temp;
Temp=* x;
* x=* y;
* y=temp;
}