当前位置:网站首页>Rough notes of C language (2) -- constants
Rough notes of C language (2) -- constants
2022-07-05 07:18:00 【After reading thousands of books, you can pick them up and put 】
Constant
C The definition forms of constants and variables in language are different .
C Language constants are divided into the following :
- Literal constants
- Const Modified constant variable
- #define Defined identifier constant
- Enumeration constants
Literal constants
For example, you can call directly “1” Nothing else, just literally
Const Modified constant variable
Const int num=4
Num by Const Modified constant variable , Has constant properties , Have constant characteristics and —— Can't change , But it's essentially a variable .
The above is a simple example to help understand , When const modification num Make it a constant variable , If you assign a value to it , Will report a mistake , because num Is already a constant variable , And have constant properties , Its value cannot be changed , But to be clear, its essence is variables .
The essential proof is that the variables are as follows :
So let's define one const Modified constant variable num. Then write it into the array


At this time, the subscript in the mapping array is 0 Then you will find that it reports an error , And in brackets , I want you to fill in the constant , At this time, we lose const Embellished num, shows num Is not a constant .

The value in the middle bracket is changed to a literal constant 8 Timely and successful .
Therefore, we should also know that the array is determining its size “【】” What should be written in brackets is a constant . When can variables be used in the brackets of an array ?
When you represent one of the arrays , Variables can be used in brackets to represent the subscript of the array .
as follows :

#define Defined identifier constant

Enumeration constants
Enumerate and enumerate one by one
Enumerate keywords enum
Each enumeration constant ( Here it means small,middle,big) There is a corresponding fixed value . So they are called “ Enumeration constants ” It can also be understood as taking a name , That name is essentially equivalent to a number .
The following helps understand : Define a variable created by enumeration s, Make it equal to small. And equal to s=0;
Variables created by enumeration types can be changed , But enumeration constants cannot be changed .
Um. ????? What do you mean by that? ???????
Variables created by enumeration types can be changed 
But enumeration constants cannot be changed 
Small It is already an enumeration constant , You can't say that you can assign it again as a variable .
边栏推荐
- 2022.06.27_ One question per day
- M2dgr slam data set of multi-source and multi scene ground robot
- Course learning accumulation ppt
- U-Boot初始化及工作流程分析
- 基于FPGA的一维卷积神经网络CNN的实现(八)激活层实现
- 你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
- [vscode] prohibit the pylance plug-in from automatically adding import
- [vscode] search using regular expressions
- Ros2 - function package (VI)
- docker安装mysql并使用navicat连接
猜你喜欢

Anaconda navigator click open no response, can not start error prompt attributeerror: 'STR' object has no attribute 'get‘

SOC_ SD_ CMD_ FSM

【无标题】

目标检测系列——Faster R-CNN原理详解

2022 PMP project management examination agile knowledge points (7)

Netease to B, soft outside, hard in
![[node] NVM version management tool](/img/26/f13a2451c2f177a86bcb2920936468.png)
[node] NVM version management tool

Ros2 - node (VII)

Concurrent programming - how to interrupt / stop a running thread?

HDU1231 最大连续子序列(分治or动规or双指针)
随机推荐
SOC_SD_CMD_FSM
What is sodium hydroxide?
How can Oracle SQL statements modify fields that are not allowed to be null to allow nulls?
Application of MATLAB in Linear Algebra (4): similar matrix and quadratic form
Don't confuse the use difference between series / and / *
Database SQL practice 4. Find the last of employees in all assigned departments_ Name and first_ name
Lexin interview process
第 2 章:小试牛刀,实现一个简单的Bean容器
SOC_SD_DATA_FSM
Unity ugui how to match and transform coordinates between different UI panels or uis
基于FPGA的一维卷积神经网络CNN的实现(八)激活层实现
npm install -g/--save/--save-dev的区别
PowerManagerService(一)— 初始化
Typescript get timestamp
Word import literature -mendeley
[vscode] prohibit the pylance plug-in from automatically adding import
ROS2——初识ROS2(一)
SD_CMD_SEND_SHIFT_REGISTER
[idea] efficient plug-in save actions to improve your work efficiency
list. files: List the Files in a Directory/Folder