当前位置:网站首页>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.
边栏推荐
- [untitled]
- LCA 板子
- C declaration and initialization and assignment
- Deep understanding of browser caching mechanism (HTTP)
- Fu Yingna: Yuan universe is the new generation of Internet!
- 对一个元素使用多种变形的方法
- Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理
- The structure pointer must be initialized, and the pointer must also be initialized
- Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
- Taobao product details interface (product details page data interface)
猜你喜欢

数据挖掘——关联分析基础介绍(上)

小程序:区域滚动、下拉刷新、上拉加载更多

Object array merges elements according to a field

C language to achieve three chess game (detailed explanation)

数据挖掘——关联分析例题代码实现(下)
![[principle] several ways of horizontal penetration](/img/fc/2ef7dd6ebc5c0bd8f7d302d8b596d6.png)
[principle] several ways of horizontal penetration

Const char* and char*, string constants

开课!看smardaten如何分解复杂业务场景

STM32F103ZET6程序移植为C8T6+C8T6下载程序flash timeout的解决方案

BGP的基础配置---建立对等体、路由宣告
随机推荐
Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
这个报错是什么鬼啊,不影响执行结果,但是在执行sql时一直报错。。。连接maxComputer是使用
Codeforces round 810 (Div. 2) d. rain (segment tree difference)
The principle of inverse Fourier transform (IFFT) in signal processing
After I get the winfrom specific control ID from the database, I need to find the corresponding control through this ID and assign a value to the text text of the control. What should I do
MySQL第四篇(完结)
How to write the filter conditions of data integration and what syntax to use? SQL syntax processing bizdate can not be
LDP -- label distribution protocol
VScode连接ssh遇到的问题
opengauss预检查安装
SQL server how to judge when the parameter received by the stored procedure is of type int?
Fu Yingna: Yuan universe is the new generation of Internet!
Change the value of the argument by address through malloc and pointer
Ma Zhixing entered the mass production of front loading, starting with the self-developed domain controller?
MPU6050
索引的最左前缀原理
Big manufacturers finally can't stand "adding one second", and companies such as Microsoft, Google meta propose to abolish leap seconds
LCA 板子
Lua language (stm32+2g/4g module) and C language (stm32+esp8266) methods of extracting relevant data from strings - collation
Ssl== certificate related concepts