当前位置:网站首页>Definition and use of constants in C language
Definition and use of constants in C language
2022-06-24 13:06:00 【51CTO】
In our life, there are things like pi (3.1415926...) And so on , This number often has a fixed value . In the process of coding ,C Language to prevent us from inadvertently changing its value , Therefore, the term constant is provided . Next, I will introduce two ways to define constants and the differences between them .
1.const Constants and their use
Format :
then , If the value is modified, the compiler will report an error . as follows ,
Screenshot of error reporting :

2.define Constants and their use
Format :
then , If the value is modified, the compiler will also report an error . as follows ,
Screenshot of error reporting :

3. The difference between the two
const A constant defined has to be a constant , It is essentially a variable , Just can't change its value .
and define The defined constants are identifier constants , It can be used as a constant .
for instance , Its use on array definitions :
If use const Defined constant , Cannot be compiled ,

While using define Defined constant , Can be compiled ,

That's all for the definition and use of constants . If the content of the article is wrong , Welcome to point out , Thank you very much ~~~
边栏推荐
- CVPR 2022 - Interpretation of selected papers of meituan technical team
- Attack Science: ARP attack
- “我这个白痴,招到了一堆只会“谷歌”的程序员!”
- Design and implementation of high performance go log library zap
- [highlights] summary of award-winning activities of Tencent cloud documents
- The pod is evicted due to insufficient disk space of tke node
- Another prize! Tencent Youtu won the leading scientific and technological achievement award of the 2021 digital Expo
- SCRM, a breakthrough in the new consumption era
- Who said that "programmers are useless without computers? The big brother around me disagrees! It's true
- Configuration (enable_*) parameter related to execution plan in PG
猜你喜欢

【概率论期末抱佛脚】概念+公式(不含参数估计)

Several common DoS attacks

Nifi from introduction to practice (nanny level tutorial) - environment

go Cobra命令行工具入门

YOLOv6:又快又准的目标检测框架开源啦

“我这个白痴,招到了一堆只会“谷歌”的程序员!”

Who said that "programmers are useless without computers? The big brother around me disagrees! It's true

Dingding, Feishu, and enterprise wechat: different business approaches

青藤入选工信部网安中心“2021年数字技术融合创新应用典型解决方案”

MySQL 外键影响
随机推荐
What should I do if I fail to apply for the mime database? The experience from failure to success is shared with you ~
Redis' contribution in the field of microservices
CVPR 2022 | 美团技术团队精选论文解读
JS和TS中常用特殊字符
A hero's note stirred up a thousand waves across 10 countries, and the first-line big factories sent people here- Gwei 2022 Singapore
从《梦华录》的争议性,谈谈数字版权作品的价值泡沫
【概率论期末抱佛脚】概念+公式(不含参数估计)
强化学习之父Richard Sutton论文:追寻智能决策者的通用模型
I enlighten a friend and my personal understanding of the six patriarchs' Tan Jing
线程同步的基石AbstractQueuedSynchronizer详解
Dingding, Feishu, and enterprise wechat: different business approaches
[database] final review (planning Edition)
Design and implementation of high performance go log library zap
Babbitt | metauniverse daily must read: 618 scores have been announced. How much contribution has the digital collection made behind this satisfactory answer
[day ui] affix component learning
What if the WordPress website forgets its password
Implement Domain Driven Design - use ABP framework - create entities
Pycharm中使用Terminal激活conda服务(终极方法,铁定可以)
Troubleshooting and optimization of files that cannot be globally searched by ordinary users in easydss video platform customization project
短信服務sms