#include<stdio.h>
#include<stdlib.h>
#define N 20
struct cell{
struct cell* left;
struct cell* right;
};
void f(int *t){ //复制的一个新的指针t,不是传进来的指针,是新的指针在来
回指向
int *a=(int*)malloc(sizeof(int)); //如果不返回这个新的指针而且赋值到原指针上,则原来的指
针指向不变
*a=6;
t=a;
}
int* f1(int *t){
int *a=(int*)malloc(sizeof(int));
*a=6;
t=a;
return t;
}
int main(){
int m=1,n=2;
int *mp=&m;
f(mp);
printf("1.after modify m==%d\n",*mp);
mp=f1(mp);
printf("2.after modify m==%d\n",*mp);
}
pointer-parameter AND return type
最新推荐文章于 2024-08-25 22:12:22 发布