yinda_peng 发表于 2023-3-19 10:54:17

用DevC++编译C教程4.7节test25.c的不明之处





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




这是为什么呢?

dolly_yos2 发表于 2023-3-19 11:06:39

pp 是 int** 类型,跨度应该是 sizeof(int*) 吧

yinda_peng 发表于 2023-3-19 11:33:06

dolly_yos2 发表于 2023-3-19 11:06
pp 是 int** 类型,跨度应该是 sizeof(int*) 吧



书上说是4啊,而且讲课视频里面vim运行了也是跨度为4,不清楚是我哪里出了问题

dolly_yos2 发表于 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.
怀疑是书上有问题

yinda_peng 发表于 2023-3-21 22:35:09

真的是楼上所说书上有问题吗,有没有大佬解惑啊

yinda_peng 发表于 2023-3-24 16:33:54

没人看,设最佳了
页: [1]
查看完整版本: 用DevC++编译C教程4.7节test25.c的不明之处