#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而不是354? 我試過這個沒有int和輸出是350 100 50 200,所以我假設問題是在整數。sizeof in struct
您沒有告訴您使用哪種編譯器,處理器,操作系統 –
不要使用'%d'打印size_t's。改用'%zu'。 – Sebivor
@BasileStarynkevitch:沒關係。所有平臺的答案都是一樣的。 –