int, char 및 struct의 크기를 확인하는 코드를 작성했습니다. 그러나 수동으로 계산 한 것보다 다른 결과를 제공합니다. 다른 결과 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 그러나 출력이
%zu
sizeof
때문에 반환
size_t
유형
%d
을 변경해야
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, btw입니다. – mafso
구조가 패딩되어 – bolov