当前位置:网站首页>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 !
边栏推荐
- Lecture 8: 1602 LCD (Guo Tianxiang)
- Making interactive page of "left tree and right table" based on jeecg-boot
- Thesis abstract translation, multilingual pure human translation
- Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
- oscp raven2靶机渗透过程
- Defense (greed), FBI tree (binary tree)
- How to translate biomedical instructions in English
- E-book CHM online CS
- 基於JEECG-BOOT的list頁面的地址欄參數傳遞
- 查询字段个数
猜你喜欢
Play video with Tencent video plug-in in uni app
翻译生物医学说明书,英译中怎样效果佳
LeetCode 732. My schedule III
翻译公司证件盖章的价格是多少
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
How to convert flv file to MP4 file? A simple solution
keil MDK中删除添加到watch1中的变量
On weak network test of special test
Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
随机推荐
[no app push general test plan
模拟卷Leetcode【普通】1414. 和为 K 的最少斐波那契数字数目
Biomedical localization translation services
mysql按照首字母排序
模拟卷Leetcode【普通】1249. 移除无效的括号
模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
How do programmers remember code and programming language?
Mise en œuvre d’une fonction complexe d’ajout, de suppression et de modification basée sur jeecg - boot
How to extract login cookies when JMeter performs interface testing
What are the characteristics of trademark translation and how to translate it?
今日夏至 Today‘s summer solstice
Simulation volume leetcode [general] 1249 Remove invalid parentheses
LeetCode 739. Daily temperature
Luogu p2141 abacus mental arithmetic test
删除外部表源数据
The internationalization of domestic games is inseparable from professional translation companies
MFC 动态创建的对话框及改变控件的大小和位置
模拟卷Leetcode【普通】1405. 最长快乐字符串
Full link voltage measurement: building three models
How to translate biomedical instructions in English