找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 274|回复: 3

Question4.1What are pointers really good for,anyway?

[复制链接]

210

主题

371

回帖

0

积分

管理员

积分
0
发表于 2013-7-2 15:35:19 | 显示全部楼层 |阅读模式

Q: What are pointers really good for, anyway?
A: They're good for lots of things, such as:

  • dynamically-allocated arrays (see questions 6.14 and 6.16)
  • generic access to several similar variables
  • (simulated) by-reference function parameters (see question 4.8 and 20.1)
  • malloc'ed data structures of all kinds, especially trees and linked lists
  • walking over arrays (for example, while parsing strings)
  • efficient, by-reference ``copies'' of arrays and structures, especially as function parameters

(Note that this is hardly a comprehensive list!)
See also question 6.8.

210

主题

371

回帖

0

积分

管理员

积分
0
 楼主| 发表于 2013-7-2 15:47:21 | 显示全部楼层
问题:指针有什么用处?
回答:它们对于很多的地方都适用:
1、动态分配数组(参考问题6.14和6.16)
2、访问几个相似的变量
3、按引用的函数参数传递
4、分配各种的数据结构,特别是数和链表
5、遍历(walking over这里是遍历的意思?还是按果子的改成“取代”好点儿)数组(例如,解析字符串)
6、更有效率的按引用“复制”数组和结构体,特别是作为函数参数
(这里并不是一个比较全面的描述列表)
参考问题6.8


205

主题

173

回帖

6925

积分

论坛元老

积分
6925
发表于 2013-7-2 16:54:10 | 显示全部楼层

回 tyrone2497谁 的帖子

tyrone2497谁:问题:指针有什么用处?
回答:它们对于很多的地方都适用:
1、动态分配数组(参考问题6.14和6.16)
2、访问几个相似的变量
3、按引用的函数参数传递
....... (2013-07-02 15:47) 
5、取代数组。(例如,解析字符串)

210

主题

371

回帖

0

积分

管理员

积分
0
 楼主| 发表于 2013-7-2 16:56:59 | 显示全部楼层

回 果子 的帖子

果子:5、取代数组。(例如,解析字符串) (2013-07-02 16:54)
嗯,这个果然专业多了,我查了很多材料,都没有给出解释,所以就按照原书中给出了。。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 13:58 , Processed in 0.099254 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表