当前位置:网站首页>C语言日记 3 常量
C语言日记 3 常量
2022-08-02 14:03:00 【宇 -Yu】
转义字符:一种特殊的字符常量,用来表示一些不可见字符
有关于常量变量的定义,这里不再赘述。我们只要知道: 不给他
数据有常量和变量组成。
在程序运行过程中,常量的值不能变,变量的值可以变。
\r表示回车:
#include<iostream>
using namespace std;
int main()
{
cout << "zhe\rshi\nyi\ndao\nqian\ndao\nti";
}

#include<iostream>
using namespace std;
int main()
{
cout << "zhe\r";
}
\\表示字符'\',\"表示双引号,\'表示单引号。ASCII字符常量占用1字节。
#include<iostream>
using namespace std;
int main()
{
cout << "zhe\\";
}

符号常量
三种声明形式,例:
1:
#include<iostream>
using namespace std;
int main()
{
const int A=5;
cout << A;
}
2:
#include<iostream>
using namespace std;
int main()
{
int const A = 5;
cout << A;
}
3:
#include<iostream>
using namespace std;
#define A 5
int main()
{
cout << A;
}
or like
#include<iostream>
using namespace std;
#define A 5
int main()
{
int c = 5, Y;
Y = c * A;
cout << Y;
}
在手打该project代码中遇到的问题:
#include<iostream>
using namespace std;
#define A=5 //这里输入=错了,不符合格式
int main()
{
cout << A;
}

书P21例2-2:
#include <iostream>
using namespace std;
void main()
{
int num, total;
const int PRICE = 30; num = 10;
total = num * PRICE;
cout << "total=" << total << endl;
}

#include <iostream>
using namespace std;
#define PRICE 30
void main()
{
int num,total;num=10;
total=num* PRICE;
cout<<"total="<<total<<endl;
}

要注意的是,符号常量与变量不同,它的值在其作用域内不能改变,也不能再被赋值。
使用符号常量的好处是含义清楚,且能做到“一改全改”。
边栏推荐
- 【VCU】详解S19文件(S-record)
- [ROS](02)创建&编译ROS软件包Package
- MobileNet ShuffleNet & yolov5 replace backbone
- 编程规范——LiteOS
- Paddle window10 environment using conda installation
- Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id ‘c
- redis分布式锁和看门狗的实现
- Deep learning framework pytorch rapid development and actual combat chapter4
- 海明校验码纠错设计原理
- Flask framework in-depth two
猜你喜欢

【c】大学生在校学习c语言常见代码

猜数字游戏,猜错10次关机(srand、rand、time)随机数生成三板斧(详细讲解!不懂问我!)

verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第九章)

Briefly write about the use and experience of PPOCRLabel

verilog学习|《Verilog数字系统设计教程》夏宇闻 第三版思考题答案(第十二章)

STM32(F407)—— 堆栈

Flask框架的搭建及入门

The IDEA of packaged jar package

Building and getting started with the Flask framework

MarkDown语法汇总
随机推荐
paddleocr window10初体验
Deep learning framework pytorch rapid development and actual combat chapter4
二级指针,数组指针,指针数组和函数指针
瑞吉外卖笔记——第10讲Swagger
第七单元 ORM表关系及操作
drf source code analysis and global catch exception
Flask framework in-depth two
drf视图组件
第十五单元 分页、过滤
Unit 12 associated serialization
Chapter6 visualization (don't want to see the version)
第十三单元 混入视图基类
8576 顺序线性表的基本操作
编程规范——LiteOS
第五单元 保持状态
run yolov5
How does Apache, the world's largest open source foundation, work?
[ROS](01)创建ROS工作空间
window10下半自动标注
Implementation of redis distributed lock and watchdog