全部博文(92)
分类: C/C++
2008-12-14 11:57:31
昨天晚上review以前看得书的时候,发现有一个被我因为以为自己理所当然了解而忽略的东西,发现还是又必要拿出来说一说的,特把次内容摘录如下,警告自己以后看书不能浮躁,不能想当然。
Point Parameters
A parameter can be a pointer,in which case the arguement pointer is copied.As with any nonreference type parameter,changes made to the parameter are made to the local copy.If the function assigns a new pointer value to the parameter,the calling pointer value is unchanged.
The fact that the pointer is copied affects only assignments to the pointer.If the function takes o pointer to a nonconst type,then the function can assign through the pointer and change the value of the object to which the pointer points:
|
如果不能理解可以这样:
p----------->address
ip = p后
p----------->address
/\
ip-------------|共同指向address所以可以改变值,但是在函数里再赋值给ip时
ip = pp;后
p--------->address
ip-------->pp's address