#include<stdio.h>enum color{
green,
red,
blue
};
enum color GetColor(enum color mc){
return mc;
}
int main(){
enum color myColor;
myColor=red;
printf("%d\n",GetColor(myColor));
return0;
}
c++中只有定义类型时才需要enum关键字,struct也如此
#include<iostream>
enum color{
green,
red,
blue
};
color GetColor(color mc){
return mc;
}
int main(){
color myColor;
myColor=red;
std::cout<<myColor<<std::endl;
return0;
}
在C中,可以用typedef定义一个别名,用这个别名声明变量,省去关键字
以结构体为例
#include<stdio.h>
typedef struct Color{
int green;
int red;
int blue;
}color;
color GetColor(color mc){
return mc;
}
int main(){
color myColor;
myColor.red=231;
myColor.red=154;
myColor.red=221;
color getColor=GetColor(myColor);
printf("%d\n",getColor.red);
return0;
}