12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
编程知识 时间:2024-12-04 12:58:00
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
在C语言中结构体里的枚举类型可以通过直接赋值或者通过枚举成员来赋值。直接赋值:#include <stdio.h>// 定义枚举类型enum Color {RED,GREEN,BLUE};// 定义结构体struct Car
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
在C语言中结构体里的枚举类型可以通过直接赋值或者通过枚举成员来赋值。
#include <stdio.h>// 定义枚举类型enum Color {RED,GREEN,BLUE};// 定义结构体struct Car {enum Color color;int year;};int main() {// 创建结构体对象并直接赋值struct Car myCar = {GREEN, 2020};// 打印结构体对象的值printf("My car's color is %d and year is %d\n", myCar.color, myCar.year);return 0;}
#include <stdio.h>// 定义枚举类型enum Color {RED,GREEN,BLUE};// 定义结构体struct Car {enum Color color;int year;};int main() {// 创建结构体对象struct Car myCar;// 通过枚举成员赋值myCar.color = BLUE;myCar.year = 2020;// 打印结构体对象的值printf("My car's color is %d and year is %d\n", myCar.color, myCar.year);return 0;}
无论采用哪种方式,都可以在结构体中赋值枚举类型。
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19