#include <stdio.h>
#include <string.h>
#include <malloc.h>
struct Student {
char name[100];
int id;
char major[50];
char address[200];
};
int main()
{
struct Student st;
strcpy(st.name, "Chuck");
st.id = 20001;
strcpy(st.major, "Computer Science");
strcpy(st.address, "1st Street");
printf("%d %d %d %d %d\n", sizeof(st), sizeof(st.name),sizeof(st.id), sizeof(st.major), sizeof(st.address));
return 0;
}
출력은 356 100 4 50 200입니다. 왜 sizeof (st)가 356이 아닌 356입니까? 그리고 나는 int를 가지지 않고 이걸 시도해 보았고 결과는 350 100 50 200이므로 문제가 정수라고 가정합니다.sizeof in struct
사용중인 컴파일러, 프로세서, 운영체제를 알려주지 않았습니다. –
'size_t'를 출력하는 데'% d '을 사용하지 마십시오. 대신에'% zu'를 사용하십시오. – Sebivor
@BasileStarynkevitch : 그건 중요하지 않습니다. 대답은 모든 플랫폼에서 동일합니다. –