【发布时间】:2021-12-04 02:30:43
【问题描述】:
我是 C 新手,我正在尝试定义这样的枚举:
enum PrimaryColor {"red","yellow","blue"}; /* can only be set to red yello or blue */
但是当我尝试编译时,我得到了这个错误
error expected identifier before string constant
完整代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
enum PrimaryColor {"red","yellow","blue"}; /* can only be set to red yello or blue */
/* enums use a number to represent the value under the hood and we can sepcify a number that represents the value
ex:
*/
enum Directions {"right","left","up","down"=100}; /* here down is reprecented by a 100 /*
/* when you specify the number reprecenting the value the number next to it will be the number before +1
ex:
*/
enum Directions {"right","left"=7,"down","up"}; /* left is reprecented by 7 so the number reprecenting the value(down) next to it is reprecented by 8 */
enum Directions {"right","left"=17,"down","up"}; /* left is reprecented by 7 so the number reprecenting the value(down) next to it is reprecented by 18 */
}
}
谢谢!
【问题讨论】: