对于一项分配,有人告诉我要创建一个函数,该函数将使用多个参数并在C中返回一个“枚举类”。但是,无论多么艰辛,有关枚举类的所有文档似乎都在C ++中我谷歌。我可以在C中使用枚举类吗?如果是这样,我将如何去做?
答案 0 :(得分:-1)
是的,C确实包含枚举(尽管“枚举类”是谈论它们的一种误导方式)。
来自https://docs.microsoft.com/en-au/cpp/c-language/c-enumeration-declarations?view=vs-2017:
可以这样声明它们:
enum DAY /* Defines an enumeration type */
{
saturday, /* Names day and declares a */
sunday = 0, /* variable named workday with */
monday, /* that type */
tuesday,
wednesday, /* wednesday is associated with 3 */
thursday,
friday
};
和变量可以这样声明/定义:
enum DAY today = wednesday;