如果想要通过局部变量修改main函数里面的值,就应该传地址才可以。
局部变量要通过指针接收,通过指针操作内存。
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
int get_a()
{
int a = 10;
return a;
}
void get_a2(int b)
{
b = 22;
}
void get_a3(int * p)
{
*p = 33;//通过 * 操作内存
}
int main(void)
{
int a = 100;
int * p = 22;
//通过 * 操作内存
/*通过指针间赋值
1、两个变量
2、建立关系
3、通过 * 操作内存
*/
int b = get_a();
printf("b ==== %d\n", b);
get_a2(b);
printf("b2 ==== %d\n", b);
//如果想通过形参改变实参的内容(值), 必须地址传递
get_a3(&b);
printf("b3 ==== %d\n", b);
printf("\n");
system("pause");
return 0;
}