I guess this specific code (with a = 5) was very popular back then. I do remember that these kinds of questions used to be popular interview questions. I found them quite annoying because if you really wanted the job, answering them felt like a gamble: Should you accurately say it is undefined behaviour? Would the interviewer know that? Or does the interviewer expect the output produced by the Visual Studio C compiler? Or do they expect the output produced by gcc? Which version of the compiler? Which compiler?
The moment such a question appeared, your chances of answering it in a way that would satisfy the interviewer immediately dropped to somewhere around 20%. Probably even lower. And if you decided to answer accurately, the odds are even worse because most interviewers I stumbled upon did not care about nor understand 'undefined behaviour' or 'sequence points'. I chose to answer accurately every time and, more than once, that left the interviewer flummoxed.
I am very glad these types of interview questions have become less prevalent these days. They have, right? Right?
magicalhippo 2 days ago [-]
Perhaps I'm just naive and/or have forgotten too much C, not that I knew that much, but I'm a bit perplexed as to why this is UB.
It seems like something that should trigger a "we should specify this" reaction when adding these operators, and there is at least one reasonable way to define it which is fairly trivial and easily implementable.
Tomte 2 days ago [-]
Some C++ quiz with ++a and a++? It‘s always about sequence points, or better the lack of sequence points.
It‘s the standard technical C++ blog post everybody seems to write.
nDRDY 2 days ago [-]
Oh god. How long before yet another UB-based question ends up in technical coding interviews?
The moment such a question appeared, your chances of answering it in a way that would satisfy the interviewer immediately dropped to somewhere around 20%. Probably even lower. And if you decided to answer accurately, the odds are even worse because most interviewers I stumbled upon did not care about nor understand 'undefined behaviour' or 'sequence points'. I chose to answer accurately every time and, more than once, that left the interviewer flummoxed.
I am very glad these types of interview questions have become less prevalent these days. They have, right? Right?
It seems like something that should trigger a "we should specify this" reaction when adding these operators, and there is at least one reasonable way to define it which is fairly trivial and easily implementable.
It‘s the standard technical C++ blog post everybody seems to write.