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?
Aucun commentaire:
Enregistrer un commentaire