Specific instructions:
1, in the process of program execution, the constant value is called a constant.
① Direct constant
Integer constants: 12, 0,-3;
Real constant: 4.6,-1.23;
Character constants: "a", "b"
② Symbolic constant
Identifier: A valid character sequence used to identify variable names, symbolic constant names, function names, array names, type names and file names.
Symbolic constants: constants are represented by identifiers. In C language, a constant can be represented by an identifier, which is called a symbolic constant.
Symbolic constants must be defined before use, and its general form is #define identifier constant, where #define is also a preprocessing command (preprocessing commands all start with "#"), which is called macro definition command (which will be further introduced in the preprocessing program later), and its function is to define identifiers as subsequent constant values. Once defined, constant values will replace all identifiers that appear in the program.
Traditionally, the identifiers of symbolic constants are in uppercase letters, and the identifiers of variables are in lowercase letters to indicate the difference.
Example 3. Use of1symbol constant. #define PRICE 30main(){ int num,totalnum = 10; Total = quantity * price; Printf("total=%d ",total); }
Constants represented by identifiers are called symbolic constants.
Symbolic constants are different from variables, and their values cannot be changed or assigned within their scope.
The advantages of using symbolic constants are:
Clear meaning;
Can "change everything".
2. The quantity whose value can be changed is called variable. A variable should have a name and occupy a certain storage unit in memory. The variable definition must be placed before the variable is used. Usually placed at the beginning of the function body. Distinguishing variable names from variable values are two different concepts.