网站运营目标,网站建设的渠道策略,企业网站的首页,wordpress 长尾词优化C语言中指针作为形参传递时#xff0c;func#xff08;*a, *b#xff09; 这种形式的话#xff0c;是无法通过简单的 ab来修改的#xff0c;在函数体内a的地址确实被修改成b的地址了#xff0c;但是当函数执行结束时#xff0c;a的地址会重新回到原本的地址里面#xf…C语言中指针作为形参传递时func*a, *b 这种形式的话是无法通过简单的 ab来修改的在函数体内a的地址确实被修改成b的地址了但是当函数执行结束时a的地址会重新回到原本的地址里面这边是由于函数执行结束函数的栈地址被释放了若是要获取a修改的地址可以采用一下两种形式获取: 形式1:return addr
#include stdio.h
#include stdint.h
#include stdbool.h
#include malloc.hstatic int * test(int*a,int*b)
{a b;return a;
}
int main(int argc, char *argv[])
{int *a NULL;int te 10;int *b te;a test(a,b);printf(a%d,*a);return 0;
}形式2采用二级指针的形式func(**a,*b)
#include stdio.h
#include stdint.h
#include stdbool.h
#include malloc.hstatic void test(int**a,int*b)
{*a b;
}
int main(int argc, char *argv[])
{int *a NULL;int te 12;int *b te;test(a,b);//传入一级指针a的地址printf(a%d,*a);return 0;
} 同样的若是要修改指针a的内容如果a为空指针在函数内调用 *a*b;就会造成段错误
#include stdio.h
#include stdint.h
#include stdbool.h
#include malloc.hstatic void test(int*a,int*b)
{*a *b;
}
int main(int argc, char *argv[])
{int *a NULL;int te 12;int *b te;test(a,b);printf(a%d,*a);return 0;
}野指针不会有这个问题因为野指针会被随机的分配一块内存空间但是实际使用中仍不建议这样使用使用野指针操作可能会踩到其他内存空间造成莫名其妙的死机并且很难排插问题。