gpt4 book ai didi

c++ - 显示占用 8 个字节的 int

转载 作者:行者123 更新时间:2023-11-28 04:23:38 25 4
gpt4 key购买 nike

<分区>

我从 https://www.geeksforgeeks.org/the-offsetof-macro/ 中获取了代码.

我在 gfg 本身提供的 ide 中运行代码。

我稍微编辑了一下代码,sizeof(int) 显示为 4,但它显示在结构中通过偏移占用 8 个字节

#include <stdio.h> 

#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT))

typedef struct PodTag
{
int i;
double d;
char c;
} PodType;

int main()
{
printf("%ld", OFFSETOF(PodType, d) );

getchar();
return 0;
}

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