鱼C论坛

 找回密码
 立即注册
查看: 2092|回复: 5

[已解决]用DevC++编译C教程4.7节test25.c的不明之处

[复制链接]
发表于 2023-3-19 10:54:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
QQ截图20230319024754.png



按理来说,pp的跨度应该4(sizeof(int)),然而编译结果跨度却是8 :


Chapter4.test25.problem.png

这是为什么呢?
最佳答案
2023-3-19 12:03:30
yinda_peng 发表于 2023-3-19 11:33
书上说是4啊,而且讲课视频里面vim运行了也是跨度为4,不清楚是我哪里出了问题

这是标准的说法
For the purposes of these operators, a pointer to an object that is not an element of an array behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type.
When an expression that has integer type is added to or subtracted from a pointer, the result has thetype of the pointer operand. If the pointer operand points to an element of an array object, and thearray is large enough, the result points to an element offset from the original element such that thedifference of the subscripts of the resulting and original array elements equals the integer expression.In other words, if the expression P points to the i-th element of an array object, the expressions(P)+N (equivalently, N+(P)) and (P)-N (where N has the value n) point to, respectively, the i + n-thand i − n-th elements of the array object, provided they exist. Moreover, if the expression P points tothe last element of an array object, the expression (P)+1 points one past the last element of the array object, and if the expression Q points one past the last element of an array object, the expression(Q)-1 points to the last element of the array object.

怀疑是书上有问题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-3-19 11:06:39 From FishC Mobile | 显示全部楼层
pp 是 int** 类型,跨度应该是 sizeof(int*) 吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-19 11:33:06 | 显示全部楼层
dolly_yos2 发表于 2023-3-19 11:06
pp 是 int** 类型,跨度应该是 sizeof(int*) 吧

QQ截图20230319033120.png

书上说是4啊,而且讲课视频里面vim运行了也是跨度为4,不清楚是我哪里出了问题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-3-19 12:03:30 | 显示全部楼层    本楼为最佳答案   
yinda_peng 发表于 2023-3-19 11:33
书上说是4啊,而且讲课视频里面vim运行了也是跨度为4,不清楚是我哪里出了问题

这是标准的说法
For the purposes of these operators, a pointer to an object that is not an element of an array behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type.
When an expression that has integer type is added to or subtracted from a pointer, the result has thetype of the pointer operand. If the pointer operand points to an element of an array object, and thearray is large enough, the result points to an element offset from the original element such that thedifference of the subscripts of the resulting and original array elements equals the integer expression.In other words, if the expression P points to the i-th element of an array object, the expressions(P)+N (equivalently, N+(P)) and (P)-N (where N has the value n) point to, respectively, the i + n-thand i − n-th elements of the array object, provided they exist. Moreover, if the expression P points tothe last element of an array object, the expression (P)+1 points one past the last element of the array object, and if the expression Q points one past the last element of an array object, the expression(Q)-1 points to the last element of the array object.

怀疑是书上有问题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-21 22:35:09 | 显示全部楼层
真的是楼上所说书上有问题吗,有没有大佬解惑啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-24 16:33:54 | 显示全部楼层
没人看,设最佳了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-24 00:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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