用 sizeof 取得 struct 的大小的困惑? |
尚未結案
|
forth
一般會員 發表:13 回覆:34 積分:9 註冊:2002-10-30 發送簡訊給我 |
typedef struct
{ unsigned int a;
unsigned int b;
unsigned short c;
unsigned short d;
unsigned short e;
unsigned short f;
} X; typedef struct
{ unsigned int a;
unsigned int b;
unsigned short c;
unsigned short d;
unsigned short e;
} Y; int a = sizeof(X);
int b = sizeof(Y); int c = sizeof(unsigned int);
int d = sizeof(unsigned short); 以上所得 a= 16, b= 16, c=4, b=2;
為什麼 a and b 會是一樣的結果,
我在 VC and DEV-C RUN 的結果都是一樣的,
難道是 sizeof 用在 struct 所得的結果要4的倍數嗎?
還是他是一個 bug 不知有誰知道? 謝! 寫程式是建設,除錯是破壞.
寫程式是樂趣,除錯是苦難.
哈! 哈! ....
|
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
|
GeorgeKu
中階會員 發表:1 回覆:120 積分:74 註冊:2004-10-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |