Examly題庫立即開始練習
2 類科共用卷
普考-電信工程普考-電子工程
計算機概要11230單選題

以下 C 語言中的結構變數定義: struct A{ union{ struct{unsigned int i; } B; struct{unsigned short s1; unsigned short s2;} C; struct{unsigned char c1; unsigned char c2; unsigned char c3; unsigned char c4;} D; }; }; struct A a; a.B.i = 0x01020304; 下列敘述何者正確?

A執行 printf("%hx", a.C.s1)將會輸出 102
B執行 printf("%hx", a.C.s2)將會輸出 304
C執行 printf("%d", a.D.c1)將會輸出 1
D執行 printf("%d", a.D.c4)將會輸出 1正確答案
答案與詳解
D
正確答案
union 共用記憶體,little-endian 下 0x01020304 低位先存,c1=0x04、c4=0x01。

為什麼答案是 D

c4 位於最高位址,little-endian 下存 0x01,%d 輸出 1,正確。union 共用記憶體,c1~c4 依序對應 04、03、02、01。

考點:位元組序誤解考點:低位址=低位元組考點:little-endian
載入中…

計算機概要 相關題目

想練更多計算機概要考古題?

Examly 收錄 38 萬+ 道歷屆題目,每題都有像這樣的精選詳解。免費下載,立即開練。

Download on theApp Store即將推出Google Play
黑皮