交换两个变量的值,关于形参实参是否变化的问题
#include<stdio.h>void ff (int a, int b);
int main(void)
{
int a = 7, b = 9;//实参
ff (a, b);
printf("a = %d, b = %d\n", a, b);
return 0;
}
void ff (int x, int y )//形参
{
int c;
c = x;
x = y;
y = c;
}
//形参变,实参不变。
////////////////////////////////////////
#include<stdio.h>
void ff (int *a, int *b);
int main(void)
{
int a = 7, b = 9;//实参
ff (&a,&b);
printf("a = %d, b = %d\n", a, b);
return 0;
}
void ff (int *x, int *y )//形参
{
int c;
c = *x;
*x = *y;
*y = c;
}
//用指针,形参变,实参也变