小弟刚学指针,谁能解释下下面的代码
#include <stdio.h>#include <stdlib.h>
int swap1();
int swap2();
int main()
{
int m = 0, n = 1;
printf("Starting values: m, n = %d, %d\n", m, n);
swap1(m, n); /* call by value */
printf("After swap1(): m, n = %d, %d\n", m, n);
swap2(&m, &n); /* call by reference */
printf("After swap2(): m, n = %d, %d\n\n", m, n);
return 0;
}
/* swap1: swaps copies of values */
int swap1(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
return 0;
}
/* swap2: swaps values at the addresses given */
int swap2(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
return 0;
为什么两个函数输出一个是01,一个是10啊?