c++ - C语言switch语法的一个问题
怪我咯
怪我咯 2017-04-17 14:41:23
0
2
553

请问图片当中这个问题,为什么答案是C呢?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
Peter_Zhu

The conditions in switch must be certain. I believe this should be the case for most languages ​​​​you come into contact with.
In other words, there should be no ambiguity between switch conditions.
In D, there may be ambiguity between condition 1 and condition c. Because c is a variable, when c equals 1, it may cause unpredictable situations in the program. So the compiler simply prohibits this situation. (Although c is assigned a value of 2 here, since it is not a constant, the compiler cannot guarantee whether the variable will be changed at runtime, so it still thinks it will cause ambiguity)
To put it simply, it is not allowed to appear in the switch condition variable. (A variable here refers to a quantity that can change the result of this conditional judgment. In swift, the syntax allows assigning conditional matching values ​​​​to variables)

刘奇

To put it simply, because A B D it’s wrong

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!