当前位置:网站首页>On the first day of clock in, click to open a surprise, and the switch statement is explained in detail
On the first day of clock in, click to open a surprise, and the switch statement is explained in detail
2022-07-06 06:34:00 【The chick is speechless】
#include<stdio.h>
int main ()
{
int n=1;
int m=2;
switch(n)
{
case 1: m++;
case 2: n++;
case 3:
switch(n)
{//switch Allow nesting
case 1: n++;
case 2: m++;
n++;
break;
}
case 4: m++;
break;
default:
printf(" Input error ");
}
printf("m=%d, n=%d",m,n);
return 0;
}
Guess the result of this string of code
Are you right ?
If you don't
Just take a good look at my following explanation !
switch( Shaping expression )// It's very important here. It must be an integer expression , If it is float=1.0, Then the code will make an error { Statement item ; }
And statement items are just some case sentence
case Equivalent to entering switch The gate of statement
case Integral constant expression ;// If appear case 1.0\case n, Sorry, there will be an error in the code sentence ;
break It's about jumping out switch Key
As the above question
n Get into switch from case 1 Compile down to case 2,case 3( As long as you don't meet break)
If you think this way , Sorry , Be careful next time !
switch (n) The point is n, This n Decide from which case Door in , As long as you don't encounter break, Our integer will be right all the way down
switch(n)
{
case 1: m++;
case 2: n++;
case 3:
switch(n)
{//switch Allow nesting
case 1: n++;
case 2: m++;
n++;
break;
}
these two items. switch(n) Just two gates , first n=1 Input , From case 1 Go down to case 3 At this time, some cute people, like me, started from case 1 Go down , Click down , Sorry , Be careful next time !
When it comes to the second switch(n) when n Already in case 2 Evolved into 2 了 , So it goes directly from case 2 Down met break, encounter break It's another pit .
It says break It's like a key to go out , But a key can only open one door , It can only make your program pop up the nearest “ } ”, The program will still go down , Until the last one pops up “ } ”.
If you are serious enough to read this article I wrote , I will be very moved , Because I don't want to read it anymore , Ha ha ha ! Thank you for clicking into my article , thank you !
边栏推荐
- Simulation volume leetcode [general] 1249 Remove invalid parentheses
- Simulation volume leetcode [general] 1109 Flight reservation statistics
- Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
- 模拟卷Leetcode【普通】1296. 划分数组为连续数字的集合
- 如何做好金融文献翻译?
- Postman core function analysis - parameterization and test report
- An article was uncovered to test the truth of outsourcing companies
- Summary of the post of "Web Test Engineer"
- How much is the price for the seal of the certificate
- 关于新冠疫情,常用的英文单词、语句有哪些?
猜你喜欢
商标翻译有什么特点,如何翻译?
In English translation of papers, how to do a good translation?
How much is it to translate Chinese into English for one minute?
Transfert des paramètres de la barre d'adresse de la page de liste basée sur jeecg - boot
Address bar parameter transmission of list page based on jeecg-boot
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Thesis abstract translation, multilingual pure human translation
Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
MySQL5.72.msi安装失败
随机推荐
Py06 dictionary mapping dictionary nested key does not exist test key sorting
How effective is the Chinese-English translation of international economic and trade contracts
Cobalt Strike特征修改
leetcode 24. 两两交换链表中的节点
Database isolation level
It is necessary to understand these characteristics in translating subtitles of film and television dramas
LeetCode 739. Daily temperature
Simulation volume leetcode [general] 1447 Simplest fraction
Play video with Tencent video plug-in in uni app
MySQL5.72. MSI installation failed
MFC关于长字符串unsigned char与CString转换及显示问题
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
Simulation volume leetcode [general] 1314 Matrix area and
Advanced MySQL: Basics (1-4 Lectures)
Simulation volume leetcode [general] 1219 Golden Miner
oscp raven2靶机渗透过程
Simulation volume leetcode [general] 1218 Longest definite difference subsequence
在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
Simulation volume leetcode [general] 1091 The shortest path in binary matrix
模拟卷Leetcode【普通】1447. 最简分数