我正在写代码来检查int,char和一些struct.But的大小,但是它给出的结果与手动计算出的结果不同。使用SIZEOF运算符计算出的结果不同吗?
#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));
}
我觉得结构应具有尺寸= 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
http://stackoverflow.com/tags/c/info。而10 * 1 + 4是14,顺便说一句。 – mafso
结构被填充 – bolov