当前位置:网站首页>标准C语言总结2
标准C语言总结2
2022-07-28 05:18:00 【c7473168】
switch开关分支语句
switch(n) //n可以是数值、表达式,运算结果必须是整数
{
case val:... //如果val==n,则打开执行开关,val必须是常量
//case a ... b 可以表示[a,b],但是只有GNU编译器才支持该语法,不建议使用
break; //关闭执行开关,结束switch,
//如果每个case都加break,形成了分支结构
//switch中不能使用continue配合
default: //如果所有的case都没有打开,则最后打开default,
//并且放在任何位置都可以最后打开
}
for循环语句
for([1];[2];[3])
{
[4]
}
[1]、给循环变量赋予初值,但只有C99以上标准才可以在此处定义循环变量 -std=gnu99
[2]、判断循环变量是否到达边界,如果没到达,进入循环
[4]、被反复执行的代码,称之为循环体
[3]、改变循环变量,防止出现死循环,一般对循环变量进行自加、自减
1、2、4、3、2、4、3 ...
for(;;) //死循环 用法
大括号问题:
1、 建议上下对齐
2、 如果循环体中只有一行代码,大括号可以省略但是不利于扩展
一般的商业代码都要求大括号不能省略
while循环语句
while(表达式)
{
//循环体
}
do while 循环语句
do{
//循环体
}while(表达式);//表达式为真循环继续,为假结束循环
类型转换
只有相同类型的数据才能运算,如果类型不相同的数据需要先转换相同类型后
再进行计算
自动类型转换:
转换规则:以不丢失数据为基础,可以适当地牺牲一些空间
1、字节少的向字节多的转
2、有符号的向无符号的转
3、整型向浮点型转
注意: char short 如果与不同类型数据运算时,
会提升为int类型后参与运算
强制类型转换:
(新类型名)数据;
这种方式有可能会丢失数据,慎重使用
边栏推荐
- BeanUtils. Copyproperties cannot copy different list sets problem solving lists.transform function
- You must configure either the server or JDBC driver (via the ‘serverTimezone)
- Distillation model diagram
- ByteBuffer. Position throws exception illegalargumentexception
- [singleton mode] thread safety of lazy mode
- C语言回顾(指针篇)
- Example of main diagram of paper model
- Video twins: the starting point of informatization upgrading of smart Parks
- openjudge:矩阵乘法
- latex使用\hl进行高亮时遇到引用总是报错,显示少了括号或者多了括号
猜你喜欢

Example of main diagram of paper model

Arrangement of main drawings of the latest 54 papers of eccv22

Custom JSON return data

JUC笔记

Redis' bloom filter

Review of Metallurgical Physical Chemistry - gas liquid phase reaction kinetics

The Monte Carlo method solves the PI and draws points with turtle, and completes the progress bar problem

树莓派串口配置

Leetcode 随即链表的深拷贝

冶金物理化学复习 -- 金属电沉积过程中的阴极极化,超电势以及阳极和阳极过程
随机推荐
There is no crossover in the time period within 24 hours
JVM篇 笔记3:类加载与字节码技术
URL 形式
List < long >, list < integer > convert each other
Review of metallurgical physical chemistry ---- gas solid reaction kinetics
ByteBuffer. Position throws exception illegalargumentexception
The essence of dynamic convolution
RESNET structure comparison
分支与循环语句
Response<T>类
集合框架的操作使用
论文模型主图范例
Mabtis(一)框架的基本使用
Mutual conversion between latex and word
标准C语言总结1
regular expression
Problems encountered when the registry service Eureka switches to nocas
FusionGAN代码学习(一)
When SQL queries the list, the data is inconsistent twice, and limit is automatically added
MySQL adds sequence number to query results