#include <stdio.h>
void fun (int c, int *d) {
c++;
(*d)++;
}
int main ( ){
int a=1, b=2;
fun(a, &b);
printf("%d, %d", a, b);
return 0;
}
这个问题结果为什么是1,3
#include <stdio.h>
void fun (int c, int *d) {
c++;
(*d)++;
}
int main ( ){
int a=1, b=2;
fun(a, &b);
printf("%d, %d", a, b);
return 0;
}
这个问题结果为什么是1,3
a是值传递,b是地址传递
所以在fun里面的运算不会影响a的值,a一直是1
&b把b的地址传给了fun函数,所以fun函数内是针对b地址的进行修改,影响了b的值,所以b本来是2,++以后变成了3