Under what circumstances will the body under the condition be executed? [duplicate]

牧云@^-^@ 提交于 2019-12-11 09:28:18

问题


Long time ago, while being interviewed, I stumbled across this question:

Suppose, somewhere, we have gotten this line of code. Could you provide at least three cases which would cause the body under the condition to be executed?

if (a == 3 && a == 4) { /* ... */ }

My answers were:

  1. It is quite possible that 'a' might be a custom class with overloaded equality operator.

  2. 'a' might be defined (or re-defined) somewhere as #define a b++, and if b equals 3, then it will be evaluated as true.

  3. There must be some kind of multithreading problem, such as, different threads access the same variable.

  4. goto label

I did not ask for the clarification, and also was not told whether my answers were right. How would you proceed? Are there any interesting answers?


回答1:


That is not a loop.

So vacuosly, every loop shown is executed.



来源:https://stackoverflow.com/questions/53586178/under-what-circumstances-will-the-body-under-the-condition-be-executed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!