作者anoymouse (没有昵称)
看板C_and_CPP
标题Re: [问题] link list 加节点在开头
时间Thu Dec 3 19:54:05 2015
所以说 当指标传进函式 它只是复制一个变数名称不同 但指到的变数型态一样的指标?
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://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1449143647.A.A78.html
1F:推 james1022jk: 其实就是call by value的问题 12/03 20:07
2F:→ anoymouse: 谢谢! 真是盲点 12/03 22:08
3F:推 ilikekotomi: 置底有提到这个 看那边有图示还蛮好懂的 12/04 20:07