gpt4 book ai didi

c - 查找内存C中指针的值

转载 作者:行者123 更新时间:2023-11-30 20:09:23 25 4
gpt4 key购买 nike

给定下面的数据集和底部显示的答案 (b36d5c),如何计算 &ptr[3] 的该值。我只是无法弄清楚它所指的数据集的哪个区域以及如何为其添加大小,但我知道答案是正确的。

sizeof(int) = 4

Data set starting at 0xb36d00 of size 128.            0xb36d00: 48 6d b3 00 00 00 00 00 4c 6d b3 00 00 00 00 00 Hm......Lm......            0xb36d10: 50 6d b3 00 00 00 00 00 30 6d b3 00 00 00 00 00 Pm......0m......            0xb36d20: 04 6d b3 00 00 00 00 00 50 6d b3 00 00 00 00 00 .m......Pm......            0xb36d30: 18 6d b3 00 00 00 00 00 1c 6d b3 00 00 00 00 00 .m.......m......            0xb36d40: 48 6d b3 00 00 00 00 00 58 6d b3 00 00 00 00 00 Hm......Xm......            0xb36d50: 44 6d b3 00 00 00 00 00 4c 6d b3 00 00 00 00 00 Dm......Lm......            0xb36d60: 00 6d b3 00 00 00 00 00 0c 6d b3 00 00 00 00 00 .m.......m......            0xb36d70: 68 6d b3 00 00 00 00 00 30 6d b3 00 00 00 00 00 hm......0m......    int array[] is stored at:        0xb36d00       int *ptr is stored at:        0xb36d28short *shortPtr is stored at:        0xb36d28          int x is stored at:        0xb36d38        short y is stored at:        0xb36d14   int ***what is defined by: (int ***)(((int **)0xb36d0c) + 2)What is the value of &ptr[3]?b36d5c

最佳答案

int *ptr 据说存储在 0xb36d28 处。 0xb36d28 处的内存包含小端顺序的 0x00b36d50(并且无论指针是四字节还是八字节,它都包含该值,因为接下来的四个字节为零)。因此,ptr 是 0xb36d50。如果指针是四个字节,则ptr[3]的地址超出0xb36d50 3•4个字节,因此为0xb36d5c。 (因为这符合已知的答案,所以我们得出结论指针是四个字节,而不是八个字节。)

关于c - 查找内存C中指针的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52711550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com