gpt4 book ai didi

c - 与使用 SIZEOF 运算符计算的结果不同?

转载 作者:太空宇宙 更新时间:2023-11-04 03:46:01 24 4
gpt4 key购买 nike

<分区>

我正在编写代码来检查 int、char 和某些结构的大小。但它给出的结果与手动计算的结果不同。

#include<stdio.h>
struct person
{
int roll;
char name[10];

};
void main()
{
struct person p1;
printf("\n The size of the integer on machine is \t :: %d \n ",sizeof(int));
printf("\n The size of the char on machine is \t :: %d \n ",sizeof(char));

printf("\n The size of structre is \t :: %d \n",sizeof(struct person));
printf("\n The size of structre is \t :: %d \n",sizeof(p1));


}

我认为结构应该有 size = 10 * 1 + 4 = 14。但是输出是

 The size of the integer on machine is   :: 4 

The size of the char on machine is :: 1

The size of structre is :: 16

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