在switch语句的第一个“案例”之前,code [英] Code before the first 'case' in a switch-statement
本文介绍了在switch语句的第一个“案例”之前,code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C有可能第一个情况
标签之前写code。是否有哪些是有用的做到这一点还是它只是一个code的死堵'任何情况下?
例如:
开关(...){
{
INT A = 0x2a;
的printf(%d个\\ N,一);
}
情况下0:
...
}
解决方案
它可以申报有限于开关
块范围变量有用的(但要注意对于这些变量的任何initialisers将被跳过):
开关(...)
{
INT N; 情况下0:
...
}
在理论上,你也可以把code那里,你能使用转到
。
In C it's possible to write code before the first case
label. Are there any cases for which it is useful to do this or is it just a 'dead block of code' ?
E.g.:
switch (...) {
{
int a = 0x2a;
printf("%d\n", a);
}
case 0:
...
}
解决方案
It can be useful to declare variables that have a scope limited to the switch
block (but be aware that any initialisers for those variables will be skipped):
switch (...)
{
int n;
case 0:
...
}
In theory, you could also put code there that you get to using goto
.
这篇关于在switch语句的第一个“案例”之前,code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文