我正在寫代碼來檢查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