本文介绍了我有个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个问题:


以下代码中j的值是多少?为什么会这样?


int i;

for(i = 0; i< 1; i ++)

{

开关(i)

{

案例0:i + = 5;

案例3:我+ = 3;

案例5:i + = 5;

休息;

}

}

int j = i;


I have a question:

What will be the value of j in the following code? and why is it so?

int i;
for( i = 0; i < 1; i++ )
{
switch( i )
{
case 0: i += 5;
case 3: i += 3;
case 5: i += 5;
break;
}
}
int j = i;

推荐答案



对于C90,没有:这是一个错误。对于C99,您怎么看?


-

Thad

For C90, nothing: it is an error. For C99, what do you think?

--
Thad




i = 5 here(no break)

i = 5 here (no break)



i = 8 here(no break)

i = 8 here (no break)



i = 13 here

i = 13 here



i = 14 here(13 + 1)

i = 14 here (13 + 1)



所以j = 14


问候奥拉夫

so j = 14

Greetings Olaf




i = 5 here(no break)case 3:i + = 3;


i = 8 here(no break)案例5:i + = 5;

i = 13这里


i = 5 here (no break) case 3: i += 3;

i = 8 here (no break) case 5: i += 5;
i = 13 here



i = 14 here(13 + 1)


i = 14 here (13 + 1)



所以j = 14


问候Olaf


so j = 14

Greetings Olaf



我问的是当它落空时,案例3如何执行?

当时i的值是5。或者它只是执行所有语句,直到看到下一个中​​断的
,无论案例陈述是什么?我知道这是一个基本的问题。我只想要一个解释。


谢谢。


what i was asking is when it falls through, how can case 3: execute?
value of i is 5 at that time. Or it just executes all statements until
a next break is seen, regardless of the case statements? I know its a
basic question. I just want an explanation.

Thanks.


这篇关于我有个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 00:59