当前位置:网站首页>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.
边栏推荐
- Spark structured stream writing Hudi practice
- PolyWorks script development learning notes (II) -treeview basic operations
- Leetcode daily question (985. sum of even numbers after queries)
- Install database -linux-5.7
- Overview of image restoration methods -- paper notes
- PowerDesigner does not display table fields, only displays table names and references, which can be modified synchronously
- Serializer rewrite: update and create methods
- Jestson Nano 从tftp服务器下载更新kernel和dtb
- Win10 quick screenshot
- 1300. sum of varied array closed to target
猜你喜欢
![Uncle Wang's blog directory [constantly updating]](/img/91/72cdea3eb3f61315595330d2c9016d.png)
Uncle Wang's blog directory [constantly updating]

Learning C language from scratch -- installation and configuration of 01 MinGW

Flink learning notes (VIII) multi stream conversion

The rise and fall of mobile phones in my perspective these 10 years

Using Hudi in idea

PolyWorks script development learning notes (I) - script development environment

Error output redirection

Arduino handles JSON data, arduinojson assistant

Win10 install elk

There is no open in default browser option in the right click of the vscade editor
随机推荐
Jestson Nano自定义根文件系统创建(支持NVIDIA图形库的最小根文件系统)
Trial of the combination of RDS and crawler
Spark 概述
用Redis实现分布式锁
Convert IP address to int
[kotlin learning] control flow of higher-order functions -- lambda return statements and anonymous functions
Hudi integrated spark data analysis example (including code flow and test results)
Common software open source protocols
专利查询网站
Flask+supervisor installation realizes background process resident
LeetCode每日一题(1362. Closest Divisors)
Leetcode daily question (931. minimum falling path sum)
Flink学习笔记(十一)Table API 和 SQL
[CSDN]C1训练题解析_第四部分_Web进阶
Hudi data management and storage overview
LeetCode每日一题(516. Longest Palindromic Subsequence)
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 1 -- establishment of engineering template -template
About the configuration of vs2008+rade CATIA v5r22
The server denied password root remote connection access
Error output redirection