当前位置:网站首页>Definition and use of enum in C language
Definition and use of enum in C language
2022-07-03 09:38:00 【Communication pawn】
Recently, I encountered the use of enumeration in my work , There are mainly two questions , How much space does enumeration variables occupy , Another
The first question is how many characters in the enumeration represent ? With two questions, I compiled a small program to verify :
#include <stdio.h>
enum enum_type_enum
{
RED,
GREEN,
BLUE,
RED_BLUE=10,
RED_GREEN
} enum_colour;
void main(void)
{
unsigned char colour_id_test=0;
printf(" Enumeration accounting %d byte \n",sizeof(enum_colour));
while(1)
{
printf("please input the colour value !\n");
scanf("%d",&colour_id_test);
switch(colour_id_test)
{
case RED:
{
printf("colour is red\n");
break;
}
case GREEN:
{
printf("colour is GREEN\n");
break;
}
case BLUE:
{
printf("colour is BLUE\n");
break;
}
case RED_BLUE:
{
printf("colour is RED_BLUE\n");
break;
}
case RED_GREEN:
{
printf("colour is RED_GREEN\n");
break;
}
default :
{
printf("the value is wrong\n");
break;
}
}/*end of switch(colour_id_test)*/
}/*end of while(1)*/
}/*end of main*/

Conclusion :
1. Enumeration variables occupy 4 Bytes , All members share 4 Byte space , So is every member 4 Bytes of space , Only one member will exist at the same time .
2. The member of the first enumeration defaults to 0. The following members add 1, If there is a member assignment , Start with this member , The following members also add 1.
边栏推荐
- 【22毕业季】我是毕业生yo~
- Call the contents of Excel cells opened at the same time - button line feed
- Database execution error: SQL_ mode only_ full_ group_ by:
- 一款开源的Markdown转富文本编辑器的实现原理剖析
- Flink learning notes (10) Flink fault tolerance mechanism
- Leetcode daily question (1362. closest divisors)
- Hudi integrated spark data analysis example (including code flow and test results)
- Esp32 at command does not respond
- Leetcode daily question (745. prefix and suffix search)
- 数字身份验证服务商ADVANCE.AI顺利加入深跨协 推进跨境电商行业可持续性发展
猜你喜欢

Solve the problem of disordered code in vscode development, output Chinese and open source code

Detailed steps of windows installation redis

There is no open in default browser option in the right click of the vscade editor

Hudi quick experience (including detailed operation steps and screenshots)

PolyWorks script development learning notes (III) -treeview advanced operation

Spark cluster installation and deployment

LeetCode每日一题(2212. Maximum Points in an Archery Competition)

Arduino handles JSON data, arduinojson assistant

Modify idea code
![[CSDN]C1訓練題解析_第三部分_JS基礎](/img/b2/68d53ad09688f7fc922ac65e104f15.png)
[CSDN]C1訓練題解析_第三部分_JS基礎
随机推荐
Leetcode daily question (745. prefix and suffix search)
Epoll read / write mode in LT and et modes
Construction of simple database learning environment
How MySQL modifies null to not null
Patent inquiry website
Flink学习笔记(九)状态编程
What do software test engineers do? Pass the technology to test whether there are loopholes in the software program
Notes on numerical analysis (II): numerical solution of linear equations
Jestson nano downloads updated kernel and DTB from TFTP server
Spark structured stream writing Hudi practice
PIP configuring domestic sources
[kotlin puzzle] what happens if you overload an arithmetic operator in the kotlin class and declare the operator as an extension function?
全球KYC服务商ADVANCE.AI 活体检测产品通过ISO国际安全认证 产品能力再上一新台阶
Convert IP address to int
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 1 -- establishment of engineering template -template
LeetCode每日一题(1996. The Number of Weak Characters in the Game)
Implementing distributed lock with redis
解决Editor.md上传图片获取不到图片地址问题
一款开源的Markdown转富文本编辑器的实现原理剖析
Database execution error: SQL_ mode only_ full_ group_ by: