What is the understanding and understanding of several constants in C language
This article shows you how to understand and understand several constants in C language. the content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
What is the constant of C language?
A constant is a quantity whose value cannot be changed while the program is running. Constants in C language can be divided into direct constants and symbolic constants. Constants are divided into: literal constants, const-modified constants, # define-defined identifier constants, enumeration constants.
2. Explain respectively 1. Literal constant
Literal constant: a value that is entered directly into the program.
For example, in myAge=19; myAge is a variable of type int, while 26 is a literal constant.
For example, float price=18.8;price is a float type variable, while 18.8 is a literal variable.
Constant variables modified by 2.const
Const defines a variable, not a constant, but the value of this variable is not allowed to change is a constant! With a type. There is type checking at compile time.
Example: const int n is called const modification constant, const modification constant in C language only limits the variable n can not be changed directly, but n is essentially a variable, so it is called constant.
Identifier variables defined by 3.#define
Define defines constants without types and only makes simple character substitutions. It works during precompilation, and there is no type checking.
4. Enumeration constant
Enumeration constants can create a new type and then define new type variables, defining the values of those variables as a set of possible values.
If there is no special instruction, the enumeration constant starts at 0 by default and increases by 1 in turn.
A few notes about enumerations:
The ① enumeration value is a constant, not a variable. You cannot assign a value to it with an assignment statement in the program.
② can only assign enumerated values to enumerated variables, not the values of elements directly.
The above is the understanding and understanding of several constants in C language. have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.