c - 打印某个变量的整个地址 block

标签 c pointers hex memory-address

<分区>

我有这个代码:

#include <stdio.h>

int main(void) {
    int a = 56;
    printf("First part of address block:\n");
    printf("%p", &a);
    printf("All parts of address block:\n");
    printf("%p\n%p\n%p\n%p", &a, &a + 1, &a + 2, &a + 3);
    return 0;
}

输出:

First part of address block:                                                        
0x7fffd029ecec                                                                               
All parts of address block:                                                                             
0x7fffd029ecec                                                                               
0x7fffd029ecf0                                                                               
0x7fffd029ecf4                                                                               
0x7fffd029ecf8  

在我看来,int a 的地址 block 看起来像这样:

| 0x7fffd029ece**c** | 0x7fffd029ece**d** | 0x7fffd029ece**e** | 0x7fffd029ece**f** |
|      0000          |      0000          |      0011          |      1000    

最佳答案

C 不是按字节递增指针,而是按所指类型的大小递增。 也就是说,如果您有指向 int 的指针,它会增加 sizeof(int) - 在您的示例中是 4。

关于c - 打印某个变量的整个地址 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55359607/

相关文章:

C++ : how can I fourier transform an array into an other array of different size using fftw3

c++ - 测试非空指针,否则返回空

c - 将二维数组传递给常量参数的函数

Python 对对象的引用以节省额外的输入

Java 十六进制字符串连接校验和

c - C 中 int 文字之间的零

c - gcc 去哪里链接库?

c - 关于getchar()函数的有趣实践

c++ - 将十六进制写入文件

c - 检测耳机插孔插入并更改音量设置