当前位置:网站首页>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!!!
边栏推荐
- Clause 31: avoid default capture mode
- SQL notes
- Analysis on the usage, response and global delivery of provide/inject
- Regular expressions in QT
- C # get all callable methods of WebService interface [webmethod]
- Chapter 18 pagination: Introduction
- Advanced C - Section 3 - character functions and string functions
- Hidden implementation and decoupling, knowing Pimpl mode
- How to lay copper in AD (aluminum designer)
- UNO
猜你喜欢
Chapter 18 pagination: Introduction
Hidden implementation and decoupling, knowing Pimpl mode
Analysis on the similarities and differences of MVC, MVP and mvvc
Gradient descent, learning rate
How to lay copper in AD (aluminum designer)
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
Reductive elimination
无限循环滚动代码阿里巴巴国际站店铺装修代码底图滚动黑色半透明显示效果自定义内容装修代码全屏显示
Chapter 13 abstraction: address space
Logical point
随机推荐
The processing flow of thread pool depends on the core parameters
UNO
[leetcode]- sliding window
rainbow
Optocoupler working principle function electric parameter application circuit
rust编程-链表:使用struct实现链表,使用堆合并k个升序链表,自定义Display
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
Introduction to QT XML
Clause 33: decltype is used for auto & type formal parameters, with std:: forward
Normal distribution (Gaussian distribution)
Analysis of the principle of V-model and its application in user defined components
自动评教脚本使用的配置
Tita performance treasure: remote one-on-one discussion
JS to realize the conversion between string and array and an interview question
[LeetCode]-滑动窗口
[LeetCode]-二分查找
General communication protocol for industrial Internet
QT direction key to move focus
135. distribute candy
PostgreSQL Guide: Insider exploration (Chapter 7 heap tuples and index only scanning) - Notes