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

Question7.28:Why doesn't sizeof tell me the size of the block of memory pointed to by a pointer?

[复制链接]

210

主题

371

回帖

0

积分

管理员

积分
0
发表于 2013-7-1 13:45:43 | 显示全部楼层 |阅读模式

Q: Why doesn't sizeof tell me the size of the block of memory pointed to by a pointer?
A: sizeof tells you the size of the pointer. There is no portable way to find out the size of a malloc'ed block. (Remember, too, that sizeof operates at
compile time, and see also question 7.27.)

210

主题

371

回帖

0

积分

管理员

积分
0
 楼主| 发表于 2013-7-1 13:52:51 | 显示全部楼层
问题:为什么sizeof不能告知我指针指向的内存块中的内存大小?
回答:sizeof告知的是指针的大小。没有什么可移植的办法得到malloc分配的内存块的大小(同时要记住,sizeof是在编译的时候起作用的,参考问题7.27)。

14

主题

65

回帖

0

积分

新手上路

积分
0
发表于 2013-7-2 00:18:23 | 显示全部楼层
翻译得不错。
现在也还是时不时地会犯错,以为sizeof(p)是指针所指的区域的大小,呵呵。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

GMT+8, 2026-2-1 12:26 , Processed in 0.085757 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

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