使用的代码
#include<stdio.h>
struct st
{
char a;
short c;
int b;
};
struct st s1;
int main()
{
printf("%p %p \n",(&s1.b)-1, &s1);
}
Run Code Online (Sandbox Code Playgroud)
如果我打印&s1.b它的地址打印0x804a01c并&s1.b-2打印0x804a018
为什么它打印相同的地址,0x804a01c如果我选择&s1.b-1?
您的打印代码可能有问题.
#include <stdio.h>
struct st
{
char a;
short c;
int b;
};
struct st s1;
int main() {
printf("%p\n", (void*)(&s1.b));
printf("%p\n", (void*)(&s1.b - 1));
printf("%p\n", (void*)(&s1.b - 2));
}
Run Code Online (Sandbox Code Playgroud)
输出:
0x403024
0x403020
0x40301c
Run Code Online (Sandbox Code Playgroud)