C语言 函数的参数只是值(包括常值,地址值)
传入 地址值 实例
#include<stdio.h>
void _test(int*q)
{
printf("1_test is q=%p\n",q); //1_test is q=000000000062FE14
*q=1; //改变a的值
q=NULL;
printf("2_test is q=%p\n",q); //2_test is q=0000000000000000
}
int main()
{
int a=10;
int *p=&a;
printf("main is p=%p\n",p); //main is p=000000000062FE14
printf("a=%d\n",a); //a=10
_test(p);
printf("main is p=%p\n",p); //main is p=000000000062FE14
printf("a=%d\n",a); //a=1
return 0;
}
传入 常值 实例
#include<stdio.h>
void _test(int b)
{
printf("1_test is b=%d\n",b); //1_test is b=10
b++;
printf("2_test is b=%d\n",b); //2_test is b=11
}
int main()
{
int a=10;
printf("1a=%d\n",a); //1a=10
_test(a);
printf("2a=%d\n",a); //2a=10
return 0;
}