当前位置:网站首页>C language learning log 1.19
C language learning log 1.19
2022-06-13 04:57:00 【Today is also a day without baldness】
enumeration :
Constant symbolization : Use symbols instead of specific numbers to represent numbers in programs .
Enumeration is a user-defined data type , It uses keywords enum Declare with the following syntax :
enum Enumeration type name { name 0,......., name n};
Enumeration type names are usually not really used , It's a name in braces , Because they are constant symbols , Their type is int, The values are from 0 To n. Such as :
enum colers{red,yellow,green};
Three constants are created ,red The value of is 0,yellow The value of is 1, and green yes 2. When you need some constant values that can be arranged , The meaning of defining enumeration is to give these constant value names .
Enumeration of automatic counting :
#include<stdio.h>
enum COLOR{RED,YELLOW,GREEN,NumCOLORS};
int main()
{
int color=-1;
char *ColorNames[NumCOLORS] = {
"red","yellow","green",
};
char *colorName = NULL;
printf(" Enter the code of your favorite color :");
scanf("%d",&color);
if( color >=0&&color < NumCOLORS){
colorName = ColorNames[color];
}else{
colorName="unknow";
}
printf(" Your favorite color is %s\n",colorName);
return 0;
}
You can also specify values when declaring enumerators , for example :
enum COLOR{RED=1,YELLOW,GREEN=5}; among YELLOW Namely 2 了 .
TIP: The values in the enumeration are const!!!
边栏推荐
- Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
- josephus problem
- Gradient descent, learning rate
- [LeetCode]-滑动窗口
- Section 4 - arrays
- Normal distribution (Gaussian distribution)
- Chapter 18 pagination: Introduction
- Section 3 - functions
- LeetCode第297场周赛(20220612)
- 无限循环滚动代码阿里巴巴国际站店铺装修代码底图滚动黑色半透明显示效果自定义内容装修代码全屏显示
猜你喜欢
Embedded hardware - read schematic
RMQ、LCA
How to lay copper in AD (aluminum designer)
How to use redis
CMB written test graphical reasoning
Mysql8.0.13 installation tutorial (with pictures)
Draw a hammer
2021tami/ image processing: exploiting deep generative priority for versatile image restoration and manipulation
CMB's written test -- data analysis
Reductive elimination
随机推荐
Reductive elimination
Createanonymousthreadx passes parameters to anonymous threads
What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM
Tita performance treasure: remote one-on-one discussion
Mysql8.0.13 installation tutorial (with pictures)
Section 2 - branch and loop statements
Vercel uses HTTP caching
C language learning log 10.5
C language learning log 10.6
Conception d'un système basé sur MVC avec javaswing JDBC
Implementing the driver registration initcall mechanism on stm32
Avantages de win8.1 et win10
自动评教脚本使用的配置
C language learning log 10.4
The processing flow of thread pool depends on the core parameters
How to understand JS expressions and JS statements
C language learning log 10.8
Analysis on the usage, response and global delivery of provide/inject
Embedded hardware: electronic components (1) resistance capacitance inductance
Colab使用教程(超级详细版)及Colab Pro/Pro+评测