当前位置:网站首页>C语言常量与变量
C语言常量与变量
2022-07-21 02:24:00 【飞Link】
一、变量
- 是装数据的容器,数据变,容器不变
- 变量在使用前要先定义,基本格式为:
变量类型名 变量名1, 变量名2 ...;
int a, b, c;
int a = 0, b, c = 0; //初始化
二、变量名
- 是由字母('-'被看做字母)和数字组成的序列,但第一个字符必须为字母
- 大小写字母是有区别的
- 如int等关键字,已被语言本身占有,不能作为变量名
三、C语言有且仅有的四种基本类型
- char:字符型,占用一个字节的长度,可以存放一个字符
- int:整形,用来装整数,长度由所在机器而定,通常占4个字节
- float:单精度浮点型
- double:双精度浮点型
四、施加在基本类型上的限定符
short int a; //int可省略不写
long int a; //int可省略不写
- short限定符尽可能的使int变短,long尽可能的使int变长
- short和int类型不小于16位,int型可以是16位和32位,long类型不小于32位,具体由所在机器而定
- signed与unsigned可用来限定char行和所有整型(包括short或long限定过的整型)
- signed整型等价于整型
- unsigned整型使得原有整型长度不变,符号位变成了数据位,仅能表示0和正数
- signed char强制char可以存储有符号正数,unsigned char强制char可以存储无符号整数,char不加任何限定,则是否有符号根据所在机器而定
a = 10; // 常量,int型
b = 10L; // 常量,long型
c = 10l; // 常量,long型
d = 10.0; // 常量,double型
e = 10.0f; // 常量,float型
f = 10.0F; // 常量,float型
五、进制
a = 31; // 10进制
b = 031; // 8进制
c = 0x31; // 16进制
六、字符常量
- 字符常量需要用单引号将字符括起来
- 字符常量也可以参与运算,实际是其对应的ASCII码参与运算
c = a + '0';
七、转义字符
转义字符 | 含义 | 转义字符 | 含义 |
---|---|---|---|
\a | 响铃符 | \\ | 反斜杠 |
\b | 回退符 | \? | 问号 |
\f | 换页符 | \' | 单引号 |
\n | 换行符 | \" | 双引号 |
\r | 回车符 | \ooo | 8进制数 |
\t | 横向制表符 | \xhh | 16进制数 |
\v | 纵向制表符 | \0 | 字符串结束的标志 |
八、字符串常量
- 用双引号包裹起来的>=0个的字符组成的序列为字符串常量
a = "I am a string";
- 字符串中的
"
用转义字符\"
表示
a = ".*\"?"
- 多个字符串可连接
a = "I am a string";
b = "I am a " "string";
a = b;
边栏推荐
- Stm32f40x minimum system
- HCIP第四天
- Solution to the problem of interval variance of valley p5142
- Introduction to C language --- operators
- C语言经典实例:21-30例:插入排序、希尔排序1、快速排序、希尔排序2、递归法、完数、斐波那契数列、公约数和公倍数、判断水仙花数统计单词个数
- ESB结合UMC云平台开发说明
- LeetCode:1260. 二维网格迁移【一维展开+拼接】
- JSON defined syntax [json]
- NFT与奢侈品文化的天然契合:NFT满足了人类寻求独特性和地位的天性
- Interesting kotlin 0x0D: intarray vs array < int>
猜你喜欢
GrayLog分布式日志组件来提高查日志效率!
[04] through the power consumption wall, what aspects should we improve "performance"?
Solve the problem that the time field is blank when kettle8.2 version table input excel output
ASTM F 814 航空航天设备用固体材料产生烟的比光密度的试验方法
推荐效果不如意,不如试试飞桨图学习
数字孪生落地高铁桥梁可视化解决方案
[email protected] )|MOF organic skeleto"/>
Nh2-mil-125 (TI) /tio2 composite nanofibers | lanthanide metal organic framework( [email protected] )|MOF organic skeleto
关于GB 2312 编码顺序的研究
Natural fit between NFT and luxury culture: NFT meets the human nature of seeking uniqueness and status
C language -- 24 Gobang
随机推荐
Experimental requirements of cy5-pna cyanine dye Cy5 labeling PNA
C语言练习题目+答案:26-30
Interesting kotlin 0x0D: intarray vs array < int>
A code implementation of non_max_suppression (NMS)
Involution: Inverting the Inherence of Convolution for Visual Recognition(CVPR2021)
pytorch利用nn.unfold重新实现卷积操作
[mathematical modeling] juvenile delinquency | stepwise regression analysis | residual analysis rcoplot
dp---背包问题
解决Kettle8.2版本錶輸入-Excel輸出時,時間字段空白
C语言力扣第32题之最长有效括号。用栈实现
Description du développement de l'ESB en combinaison avec la plateforme UMC Cloud
Digital marketing has become a trend for small programs to break the situation
数字孪生技术海上风电场解决方案
resttemplate调用post\get
嵌入式学习:Cortex-M系列芯片介绍
Golang collection: custom types and method sets
Solve the problem that the time field is blank when kettle8.2 version table input excel output
苹果公司发布watchOS 8.7 包含错误修复和安全更新
一种非极大值抑制(non_max_suppression, nms)的代码实现方式
Demystifying Closures, Futures and async-await in Rust–Part 3: Async & Await