当前位置:网站首页>C programming language (2nd Edition) -- Reading Notes -- 1.4
C programming language (2nd Edition) -- Reading Notes -- 1.4
2022-07-27 11:28:00 【YovaVan】
Look at symbolic constants . Used in the program 300、20 And so on “ Magic number ” Not a good habit , They can hardly provide any information to people who will read the program later , And make it difficult to modify the program . One way to deal with these numbers is to give them meaningful names .#define The instruction can put the symbol name ( Symbolic constant ) Defined as a specific string :
#define name replace text
After the definition , All that appear in the program are #define Name defined in ( It is not locked with quotation marks , Nor is it part of any other name ) Will be replaced with the corresponding replacement text . among , The name has the same form as the ordinary variable name : A sequence of letters and numbers beginning with letters ; The replacement text can be any sequence of characters , Not limited to numbers .
#include <stdio.h>
#define LOWER 0 /* lower limit of table */
#define UPPER 300 /* upper limit of table */
#define STEP 20 /* step size */
/*print Fahrenheit-Celsius table*/
main()
{
int fahr ;
for (fahr = LOWER ;fahr <= UPPER; fahr = fahr + STEP )
printf ("%3d %6.1d\n",fahr , (5.0 /9.0)*(fahr - 32));
}
among ,LOWER、UPPER And STEP Are all symbolic vectors , Not variables , So it doesn't need to appear in the declaration .
Symbolic Constant names are usually spelled in uppercase letters , It is easy to distinguish variable names spelled in lowercase letters . Be careful #define There is no semicolon at the end of the instruction line .
边栏推荐
- Properties file
- Basic use of cmake
- 博弈论 AcWing 894. 拆分-Nim游戏
- Wechat push - template message parameter configuration
- JVM judges that the object is dead, and practices verify GC recycling
- 349两个数组的交集和01两数之和
- Stack acwing 3302. Expression evaluation
- 栈 AcWing 3302. 表达式求值
- Solutions to errors in tensorflow operation
- (7) Process control
猜你喜欢
随机推荐
SQL Server2000 database error
MySQL installation (RPM package)
求组合数 AcWing 887. 求组合数 III
Gaussian elimination acwing 883. solving linear equations with Gaussian elimination
7 row K with the weakest combat effectiveness in the matrix
(9) Shell I / O redirection
ACM warm-up Exercise 1 in 2022 summer vacation (summary)
Kepserver configuration
Real time development platform construction practice, in-depth release of real-time data value - 04 live broadcast review
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
Longest ascending subsequence model acwing 482. Chorus formation
Internal and external troubles of digital collection NFT "boring ape" bayc
背包问题 AcWing 9. 分组背包问题
高斯消元 AcWing 884. 高斯消元解异或线性方程组
力扣——10. 正则表达式匹配
Knapsack model acwing 1024. Packing problem
Find the combination number acwing 885. find the combination number I
Tree DP acwing 285. dance without boss
The difference between extern and static
15 design movie rental system






