当前位置:网站首页>Enumeration type
Enumeration type
2022-07-28 14:57:00 【Swlaaa】
Enumeration type (enumeration) yes C++ A derived data type in , It's a collection of user-defined enumeration constants .
If a variable has only a few possible values , It can be defined as enumeration (enumeration) type . So-called " enumeration " It means to list the values of variables one by one , The value of a variable can only be in the range of listed values .
Create enumeration , Keyword required enum. The general form of enumeration type is :
enum Enum name {
identifier [= Integer constant ],
identifier [= Integer constant ],
...
identifier [= Integer constant ]
} Enumerate variables ;If the enumeration is not initialized , I.e. omit "= Integer constant " when , Start with the first identifier .
for example , The following code defines a color enumeration , Variable c The type of color. Last ,c To be an assignment "blue".
enum color { red, green, blue } c;
c = blue;By default , The value of the first name is 0, The value of the second name is 1, The value of the third name is 2, And so on . however , You can also assign a special value to the name , Just add an initial value . for example , In the enumeration below ,green The value of is 5.
enum color { red, green=5, blue };ad locum ,blue The value of is 6, Because by default , Each name will be larger than the one before it 1, but red The value of is still 0.
边栏推荐
- Namespace conflict problem
- Tensorflow GPU installation process record
- Deploy flask on Alibaba cloud server
- The 35 required questions in MySQL interview are illustrated, which is too easy to understand
- Qt development tips
- Install scikit learn journey
- Animation mechanism of swiftui
- It's so hot that solar power can't take off? Hello, head
- MITK create module
- 8、 C scope rules
猜你喜欢
随机推荐
CONDA create, CONDA install, CONDA update error conda.core.subdir_ data.Response304ContentUnchanged
10、 C enum enumeration
Chapter II linear table
Qtableview in QT sets three methods of paging display [easy to understand]
Why can the anonymous functions of JQ access the methods inside
Redis-Redis在Jedis中的使用
MQTT入门级简单介绍与使用
数字化转型安全问题频发,山石网科助力数字政府建设
7月29日 ApacheCon|Apache Pulsar 在 vivo 的探索与实践 即将开播
C语言库函数getchar()怎么使用
linux安装redis
Solve blast database error: error pre fetching sequence data
22、 TF coordinate transformation (II): static coordinate transformation
C language program: judging triangles
Simple data analysis using Weka and excel
C callback function, interface function pointer as function parameter, function pointer as structure member
C language: mathematical method of converting decimal system into binary system
看了就会的 Rainbond 入门教程
16、 Launch file label of ROS (II)
4、 C language operators









