当前位置:网站首页>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 .
边栏推荐
- The difference between NPM install -g/-save/-save-dev
- ModuleNotFoundError: No module named ‘picamera‘
- Inftnews | drink tea and send virtual stocks? Analysis of Naixue's tea "coin issuance"
- Ros2 - configuration development environment (V)
- window navicat连接阿里云服务器mysql步骤及常见问题
- 【软件测试】05 -- 软件测试的原则
- 第 2 章:小试牛刀,实现一个简单的Bean容器
- docker安装mysql并使用navicat连接
- Import CV2, prompt importerror: libcblas so. 3: cannot open shared object file: No such file or directory
- Concurrent programming - how to interrupt / stop a running thread?
猜你喜欢
ROS2——ROS2对比ROS1(二)
The problem of configuring opencv in qt5.13.2 is solved in detail
Special training of C language array
【软件测试】04 -- 软件测试与软件开发
Matrix and TMB package version issues in R
IPage can display data normally, but total is always equal to 0
DataGrid offline installation of database driver
[software testing] 03 -- overview of software testing
Docker installs MySQL and uses Navicat to connect
Altimeter data knowledge point 2
随机推荐
【无标题】
Brief description of inux camera (Mipi interface)
【软件测试】05 -- 软件测试的原则
全局变量和静态变量的初始化
Literacy Ethernet MII interface types Daquan MII, RMII, smii, gmii, rgmii, sgmii, XGMII, XAUI, rxaui
[node] differences among NPM, yarn and pnpm
[software testing] 05 -- principles of software testing
[idea] efficient plug-in save actions to improve your work efficiency
M2DGR 多源多场景 地面机器人SLAM数据集
Course learning accumulation ppt
SD_ CMD_ SEND_ SHIFT_ REGISTER
Jenkins reported an error. Illegal character: '\ufeff'. Class, interface or enum are required
C learning notes
Ros2 - Service Service (IX)
Batch convert txt to excel format
Ros2 - node (VII)
氢氧化钠是什么?
What does soda ash do?
Now there are HTML files and MVC made with vs (connected to the database). How can they be connected?
Ros2 - workspace (V)