#include#include //动态内存跨函数使用void f(int ** q){ int j = 20; printf("_______f函数里替换前输出___________\n"); printf("*q的值即*p的地址是%d\n",*q); printf("**q的值即*p的值是%d\n",**q); *q = (int * )malloc(sizeof(int)); **q = j; printf("_______f函数里替换后输出___________\n"); printf("*q的值即*p的地址是%d\n",*q); printf("**q的值即*p的值是%d\n",**q); }int main(void){ int i = 10; int * p ; p = &i; printf("_______main函数调用f函数之前的输出________\n"); printf("i的地址是%d\n",&i); printf("p的地址是%d\n",&p); printf("*p的值是%d\n",*p); printf("*p的地址是%d\n",&*p); f(&p); printf("_______main函数调用f函数之后的输出________\n"); printf("i的地址是%d\n",&i); printf("p的地址是%d\n",&p); printf("*p的值是%d\n",*p); printf("*p的地址是%d\n",&*p); return 0;}
输出结果:
微信公众号: