Chinaunix首页 | 论坛 | 博客
  • 博客访问: 544585
  • 博文数量: 92
  • 博客积分: 2511
  • 博客等级: 少校
  • 技术积分: 932
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-19 10:10
文章分类
文章存档

2011年(6)

2010年(27)

2009年(37)

2008年(22)

我的朋友

分类: 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:

void reset(int* ip)
{
   *ip = 0;//changes the value of the object to which ip points

   ip = 0;//changes only the local value of ip,the argument is unchanged

}

如果不能理解可以这样:

p----------->address

ip = p后

p----------->address

               /\

ip-------------|共同指向address所以可以改变值,但是在函数里再赋值给ip时

ip = pp;后

p--------->address

ip-------->pp's address

阅读(696) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~