当前位置:网站首页>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.
边栏推荐
- LeetCode每日一题(1300. Sum of Mutated Array Closest to Target)
- Spark overview
- Common formulas of probability theory
- Quickly use markdown to edit articles
- LeetCode每日一题(1162. As Far from Land as Possible)
- MySQL Data Definition Language DDL common commands
- DSP data calculation error
- Overview of image restoration methods -- paper notes
- Leetcode daily question (516. long palindromic subsequence)
- Notes on numerical analysis (II): numerical solution of linear equations
猜你喜欢
一款开源的Markdown转富文本编辑器的实现原理剖析
Flink学习笔记(九)状态编程
MySQL environment variable configuration
Leetcode daily question (2212. maximum points in an archery competition)
Flink learning notes (VIII) multi stream conversion
Django operates Excel files through openpyxl to import data into the database in batches.
The rise and fall of mobile phones in my perspective these 10 years
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 2 --blinker_ Hello_ WiFi (lighting technology - Mobile App control routine)
Construction of simple database learning environment
Spark 结构化流写入Hudi 实践
随机推荐
Navicat, MySQL export Er graph, er graph
LeetCode每日一题(968. Binary Tree Cameras)
Send mail using WP mail SMTP plug-in
1922. Count Good Numbers
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 1 -- establishment of engineering template -template
专利查询网站
1300. sum of varied array closed to target
Leetcode daily question (1362. closest divisors)
307. Range Sum Query - Mutable
Integrated use of interlij idea and sonarqube
There is no open in default browser option in the right click of the vscade editor
Leetcode daily question (1162. as far from land as possible)
LeetCode每日一题(1856. Maximum Subarray Min-Product)
ERROR: certificate common name “www.mysql.com” doesn’t match requested host name “137.254.60.11”.
Hudi quick experience (including detailed operation steps and screenshots)
The rise and fall of mobile phones in my perspective these 10 years
LeetCode每日一题(516. Longest Palindromic Subsequence)
Flink learning notes (VIII) multi stream conversion
解决Editor.md上传图片获取不到图片地址问题
1922. Count Good Numbers