#include <stdio.h> #include <malloc.h> //動態內存跨函數使用 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; }
輸出結果:微信
微信公衆號:
ide