当前位置:网站首页>C语言:枚举知识点总结
C语言:枚举知识点总结
2022-07-29 04:12:00 【白的夜gxw】
使用枚举类型声明符号名称来表示整形常量。使用enum关键字,可以创建一个新“类型”并指定他可具有的值(实际上,enum常量是int类型,因此,只要能使用int类型的地方就可以使用枚举类型)。枚举类型的目的是提高程序的可读性。
枚举类型
可以使用枚举类型声明符号来表示整形常量。使用enum关键字,可以创建一个新类型并指定他可具有的值(实际上,enum常量是int类型,因此,只要能使用int类型的地方就可以使用枚举类型)。枚举类型的目的是提高程序的可读性。
enum spectrum { red,orange,yellow,green,blue,violet}; enum spectrum color;int c; color = blue; if(color==red) ...; for(color=red;color<=violet;color++) ...;enum常量
从技术层面看,red,blue等这些枚举符都是int类型的常量。在声明数组时,可以用枚举常量表示数组的大小,在switch语句中可以用枚举常量作为标签。枚举的默认值
默认情况下,枚举列表中的值都是从0开始。
在枚举的声明中,可以为枚举常量指定整数值
enum feline { low=100,med=200,high=300};如果只给一个枚举常量赋值,没有对后面的枚举常量赋值,那么后面的常量会被赋予后续的值。
enum feline { cat,lmj=100,jijia,lop};那么cat的值是0,lmj的值是100,jijia的值是101,lop的值是102.
边栏推荐
- Taobao product details interface (product details page data interface)
- Methods of using multiple deformations on an element
- Safari's compatibility with Z-index
- Design of environment detection system based on STM32 and Alibaba cloud
- Database SQL statement realizes function query of data decomposition
- Object array merges elements according to a field
- 全屋WiFi方案:Mesh路由器组网和AC+AP
- [paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation
- Opengauss pre check installation
- Lua language (stm32+2g/4g module) and C language (stm32+esp8266) methods of extracting relevant data from strings - collation
猜你喜欢

MPU6050
![[deep learning CPU (part outside) - virtual memory]](/img/f7/4c72d583456f6f68c52424602ff5d9.png)
[deep learning CPU (part outside) - virtual memory]

How to solve the problem of store ranking?

Data mining -- code implementation of association analysis example (Part 2)

Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)

Beginner: array & String

First knowledge of C language (3)

Note: restframe work records many to one tables, how to serialize in that table (reverse query)

Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理

LDP -- label distribution protocol
随机推荐
SQL window function
Code or script to speed up the video playback of video websites
Methods of using multiple deformations on an element
C declaration and initialization and assignment
openFeign异步调用问题
[introduction to C language] zzulioj 1031-1035
为什么opengauss启动的时候这么多的unknown?
MySQL Part 4 (end)
Wechat applet monitors sliding events on the screen
数据集成这个地方的过滤条件该咋写,用的啥语法?sql语法处理bizdate可以不
伏英娜:元宇宙就是新一代互联网!
LCA 板子
基于STM32和阿里云的环境检测系统设计
The return value of the function is the attention of the pointer, the local variables inside the static limit sub function, and how the pointer to the array represents the array elements
Rhel8 patch package production
MySQL gets the maximum value record by field grouping
[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation
STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案
对一个元素使用多种变形的方法
3. Solve pychart's error unresolved reference 'selenium' unresolved reference 'webdriver‘