constant
The definition forms of constants and variables in C language are different.
The constants in C language are divided into the following types:
- literal constant
- Constant variable modified by Const
- #define defined identifier constant variable
- enum constants
Literal constants
For example, if you directly type "1", nothing else is the literal meaning.
Constant variables modified by Const
Const int num=4
Num is a constant variable modified by Const. It has constant attributes, constant characteristics and - cannot be changed, but it is still a variable in essence.
The above is a simple example to help understand. When const modifies num to make it a constant variable, if you assign a value to it, an error will be reported. Because num is already a constant variable and has constant attributes, its value cannot be changed, but be clear. It is essentially a variable.
Its essence proves that the variables are as follows:
first define a constant variable num modified by const. Then write it into the array
At this time, if you type the subscript 0 in the array, you will find that it reports an error, and in the square brackets, you are asked to fill in the constant. At this time, what we lose is the const-modified num, which means that num is not a constant.
When the value in the square brackets is changed to the literal constant 8, it is successful.
From this, you should also know that when determining the size of an array, constants should be written in the brackets in "[]". When can variables be used within square brackets of an array?
When you represent an item in an array, you can use a variable in the square brackets to represent the subscript of the array.
as follows:
#define defined identifier constant
Enumeration constants
Enumeration and enumeration
enumeration keyword enum
Each enum constant (here refers to small, middle, big) has a corresponding fixed value. So they are called "enumeration constants", which can also be understood as giving them a name. That name is essentially equivalent to a number.
The following helps to understand: define a variable s created by the enumeration and make it equal to small. and is equivalent to s=0;
Variables created by enumeration types can be changed, but enumeration constants cannot be changed.
Um? ? ? ? ? What does it mean? ? ? ? ? ? ?
The variables created by the enumeration type can be changed
But enumeration constants cannot be changed
Small is already an enumeration constant, you can't assign it as a variable anymore.