问题
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:
It is quite possible that 'a' might be a custom class with overloaded equality operator.
'a' might be defined (or re-defined) somewhere as
#define a b++
, and if b equals 3, then it will be evaluated astrue
.There must be some kind of multithreading problem, such as, different threads access the same variable.
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