From Wikipedia, the free encyclopedia
列舉或枚舉(enumeration / enum)係一種數據類型。一個枚舉類型會有若干個離散嘅可能數值,例如「啤牌花色」呢個枚舉有「葵扇」、「紅心」、「鑽石」同「梅花」四個可能數值。如果有個變數屬「啤牌花色」呢個枚舉,噉佢嘅數值一定會有嗰四個數值嘅其中一個。
enum cardsuit {
Clubs,
Diamonds,
Hearts,
Spades
};
struct card {
enum cardsuit suit;
short int value;
} hand[13];
enum cardsuit trump;
C亦都容許開發者明確記得列舉常數嘅值,甚至唔使寫明類型。例子:
enum cardsuit {
Clubs = 1,
Diamonds = 2,
Hearts = 4,
Spades = 8
};
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.