当前位置:网站首页>Symbolic constant, const qualifier
Symbolic constant, const qualifier
2022-06-12 13:21:00 【Kun Li】
#define INT_MAX 32767stay cpp During compilation , First pass the source code to the preprocessor . ad locum ,#define and #include equally , It is also a preprocessor compilation instruction . The compile instruction tells the preprocessor : Find... In the program INT_MAX, And will all INT_MAX Are replaced with 32767. therefore #define Compile instructions work in a similar way to the global search and replace command in a text editor or word processor . The modified program will be compiled after these substitutions . The preprocessor looks for independent tags ( Separate words ), Skip embedded words . in other words , The preprocessor will not PINT_MAXTM Replace with P32767TM. You can also use #define To define your own symbolic constants , However #define The compile instruction is C The legacy of language ,cpp There is a better way to create symbolic constants , Use keywords const, So it won't be used often #define, However , Some header files , Especially those designed for c and cpp Header file in , You have to use #define.
The symbolic name indicates what the constant represents , in addition , If the program uses the same constant in multiple places , When you need to modify the constant , Just modify one symbol definition . have access to const Keyword to modify variable declaration and initialization , Such as
const int Months=12;After the constant is initialized , Its value is fixed , The compiler will not allow you to modify the value of this constant .g++ Will indicate that the program attempted to assign a value to a read-only variable , keyword const It's called a qualifier , Because it defines the meaning of the declaration . A common practice is to capitalize the first letter of the name , Reminded Months It's a constant , Another convention is to capitalize the entire name , Use #define This Convention is often used when creating constants , The general format for creating constants is as follows :
const type name = value;If you do not provide a value when declaring a constant , Then the value of the constant will be indeterminate , And cannot be modified .const Than #define good , First , It can clearly indicate the type . secondly , have access to cpp Scope rules restrict definitions to specific functions or files , Third , Can be const For more complex types .
边栏推荐
- Itk:: neighborhood get 6 neighborhood, 18 neighborhood, 26 neighborhood, 18/6 neighborhood, 26/18 neighborhood
- 干货满满,这些知识你必须拿下
- A "murder case" caused by ES setting operation
- Openstack network
- verilog-mode的简要介绍
- 【云原生 | Kubernetes篇】深入了解Deployment(八)
- What is the function tag? Article to understand its role and its best practices
- unittest框架
- import torch_geometric 第一个图网络例子
- MUI登录数据库完善与AJAX异步处理【MUI+Flask+MongoDB+HBuilderX】
猜你喜欢

C#DBHelper_FactoryDB_GetConn

嵌入式系统硬件构成-嵌入式系统硬件体系结构

Further understanding of the network

用PyTorch进行语义分割

实战 | 巧用位姿解算实现单目相机测距

How to solve the problem of data table query error when SQLite writes the registration function?

Getting to know blob objects

Source of routing information

IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V

Pre research of image scanning tool
随机推荐
嵌入式系统概述2-嵌入式系统组成和应用
Detect whether the vector has an intersection
[cloud native | kubernetes] kubernetes networkpolicy
R language Visual facet chart, hypothesis test, multivariable grouping t-test, visual multivariable grouping faceting bar plot, adding significance level and jitter points
IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V
Newoj week 10 question solution
嵌入式系统概述3-嵌入式系统的开发流程和学习基础、方法
Bitmap, bloom filter and hash sharding
Design virtual network to realize communication between virtual machine instance and external network
ITK multi-stage registration
The goods are full. You must take this knowledge
[embedded] serial communication and its case
C语言【23道】经典面试题【下】
章鱼网络进展月报 | 2022.5.1-5.31
import torch_ Geometric first graph network example
There was an error installing mysql. Follow the link below to CMD
实战 | 巧用位姿解算实现单目相机测距
Dameng database DM8 Windows environment installation
Help you with everything from the basics to the source code. Introduce the technology in detail
leetcode 47. Permutations II full permutations II (medium)