当前位置:网站首页>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 .
边栏推荐
- Longest ascending subsequence model acwing 482. Chorus formation
- Find the combination number acwing 885. find the combination number I
- 高斯消元 AcWing 883. 高斯消元解线性方程组
- Solutions to errors in tensorflow operation
- SQL Server2000 database error
- (8) Shell function
- Caused by:org.gradle.api.internal. plugins . PluginApplicationException: Failed to apply plugin
- 区间问题 AcWing 906. 区间分组
- 349 sum of intersection of two arrays and 01
- (4) Operator
猜你喜欢

数字三角形模型 AcWing 1018. 最低通行费

NFT leaderboard -nft real offer latest address: NFT leaderboard.com

高斯消元 AcWing 884. 高斯消元解异或线性方程组

Find the combination number acwing 888. find the combination number IV

Backpack model acwing 1022. Collection of pet elves

Kangaroo cloud stack based on CBO in spark SQL optimization

State compression DP acwing 91. shortest Hamilton path

Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?

Vscode establishes automatic search of header files under non engineering directories

Basic use of cmake
随机推荐
求组合数 AcWing 886. 求组合数 II
状态压缩DP AcWing 91. 最短Hamilton路径
Vscode establishes automatic search of header files under non engineering directories
Gaussian elimination acwing 884. Gaussian elimination for solving XOR linear equations
9 UAV array
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
10 complete half of the questions
Knapsack problem acwing 9. grouping knapsack problem
Kepserver configuration
Win10 vscode code code format setting and remote breakpoint debugging
First experience of three.js: simulating the growth of a small branch
【着色器实现Shake随机摇动效果_Shader效果第十篇】
2022 Niuke multi school training (3) a-ancestor topic translation
Game theory acwing 891. Nim game
Wenzhou University X kangaroo cloud: how to "know well" in the construction of higher talent education
PAT(乙级)2022年夏季考试
Solutions to errors in tensorflow operation
The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
Today's code farmer girl summarized her notes about NPM package management and URL module
FAQs of "relay chain" and "dot" in Poka ecosystem