当前位置:网站首页>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 ~~~
边栏推荐
- 解析nc格式文件,GRB格式文件的依赖包edu.ucar.netcdfAll的api 学习
- 线程同步的基石AbstractQueuedSynchronizer详解
- About me, a 19 line programmer
- 短信服務sms
- IIS WCF 808 port service access exception
- Another prize! Tencent Youtu won the leading scientific and technological achievement award of the 2021 digital Expo
- The programmer's graduation project is still bald after a year
- Understanding openstack network
- Metamask项目方给Solidity程序员的16个安全建议
- 几种常见的DoS攻击
猜你喜欢
随机推荐
关于被黑数据库那些事
钉钉、飞书、企业微信:迥异的商业门道
"Interesting" is the competitiveness of the new era
Configure Yum proxy
天猫618农产品“百强县” 35个县域来自中西部及东北
A scheme for crawlers to collect public opinion data
谁是鱼谁是饵?红队视角下蜜罐识别方式汇总
我开导一个朋友的一些话以及我个人对《六祖坛经》的一点感悟
CVPR 2022 - Interpretation of selected papers of meituan technical team
Implement Domain Driven Design - use ABP framework - create entities
go Cobra命令行工具入门
CVPR 2022 | 美团技术团队精选论文解读
From theory to practice, decipher Alibaba's internal MySQL optimization scheme in simple terms
A hero's note stirred up a thousand waves across 10 countries, and the first-line big factories sent people here- Gwei 2022 Singapore
【概率论期末抱佛脚】概念+公式(不含参数估计)
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
"I, an idiot, have recruited a bunch of programmers who can only" Google "
一纸英雄帖,激起千层浪,横跨10国,一线大厂都派人来了!-GWEI 2022-新加坡
Internet of things? Come and see Arduino on the cloud
YOLOv6:又快又准的目标检测框架开源啦









