Re: [問題] link list 加節點在開頭
所以說 當指標傳進函式 它只是複製一個變數名稱不同 但指到的變數型態一樣的指標?
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
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
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):