当前位置:网站首页>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!!!
边栏推荐
- C disk lossless move file
- Regular expressions in QT
- MySQL8.0.13安装教程(有图)
- All blog navigation
- Four methods for judging JS data types and user-defined methods
- Draw a hammer
- Trust programming - linked lists: use struct to implement linked lists, use heap to merge K ascending linked lists, and customize display
- Conception d'un système basé sur MVC avec javaswing JDBC
- 2022 chlorination process operation certificate examination question bank and simulation examination
- Force deduction 121 questions
猜你喜欢

How to use redis

The games that you've tasted

The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes

QT brushes and brushes

Normal distribution (Gaussian distribution)

C disk lossless move file

Gradient descent, learning rate

Spice story

Design system based on MVC using javeswingjdbc

PowerShell: because running scripts is prohibited on this system, the solution
随机推荐
Clause 26: avoid overloading universal reference types
Little C's Notepad
Shell variable learning notes
What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM
Section 3 - functions
Configuration used by automatic teaching evaluation script
Clause 33: decltype is used for auto & type formal parameters, with std:: forward
Cesium:cesiumlab makes image slices and loads slices
Third party comment plugin
All blog navigation
shell变量学习笔记
What is the saturate operation in opencv
Explain the differences and usage scenarios between created and mounted
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
QT using layout manager is invalid or abnormal
Kaggle 时间序列教程
C language learning log 10.6
Cesium:CesiumLab制作影像切片与切片加载
LeetCode第297场周赛(20220612)
Conception d'un système basé sur MVC avec javaswing JDBC