Re: [問題] link list 加節點在開頭

看板C_and_CPP作者 (沒有暱稱)時間8年前 (2015/12/03 19:54), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串2/2 (看更多)
所以說 當指標傳進函式 它只是複製一個變數名稱不同 但指到的變數型態一樣的指標? void test(int*); int *p; int main(int argc, char *argv[]) { p=(int*)malloc(sizeof(int)); *p=8; printf("%d and p's address: %d\n",*p,&p); test(p); printf("%d and p's address: %d\n",*p,&p); system("PAUSE"); return 0; } void test (int* i) { int *s= (int*)malloc(sizeof(int)); *s=100; i=s; } 也就是說我p在裡面(i)就算所指的位址跟s一樣 但已經跟p無關了 對嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.169.176.162 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1449143647.A.A78.html

12/03 20:07, , 1F
其實就是call by value的問題
12/03 20:07, 1F

12/03 22:08, , 2F
謝謝! 真是盲點
12/03 22:08, 2F

12/04 20:07, , 3F
置底有提到這個 看那邊有圖示還蠻好懂的
12/04 20:07, 3F
文章代碼(AID): #1MO2rVfu (C_and_CPP)
文章代碼(AID): #1MO2rVfu (C_and_CPP)