当前位置:网站首页>标准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类型后参与运算
强制类型转换:
(新类型名)数据;
这种方式有可能会丢失数据,慎重使用
边栏推荐
猜你喜欢

冶金物理化学复习 --- 复杂反应的速率方程

Review of Metallurgical Physical Chemistry - gas liquid phase reaction kinetics

shell运行原理

GD32F407 移植FreeRTOS+Lwip

Video twins: the starting point of informatization upgrading of smart Parks

Framework step by step easy-to-use process

Thesis writing function words

c语言:通过一个例子来认识函数栈帧的创建和销毁讲解

多模块打包:程序包:xxx不存在

JUC笔记
随机推荐
openjudge:找出全部子串位置
JVM篇 笔记4:内存模型
24小时内的时间段无交叉
链表中关于快慢指针的oj题
Framework step by step easy-to-use process
Simpledateformat thread unsafe and datetimeformatter thread safe
函数基础知识以及特殊点
Thesis writing function words
顺序表oj之合并两个有序数组
论文写作用词
Mybats foreach multi select query, index loop, and cancel the and/or tag
Mutual conversion between latex and word
冶金物理化学复习 -- 金属电沉积过程中的阴极极化,超电势以及阳极和阳极过程
Feignclient calls the get method and reports an error resultvo{result= unknown exception. Exception details: request method 'post' not supported
Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade
Digital twin technology creates visual application of smart mine
visio如何精确控制图形的大小和位置及角度
A file upload tool website written by individuals
IO流的使用
RESNET structure comparison