compiler interview questions
-
hi,
i have a nice compiler related question:int a,i; (i++)=a; (++i)=a; which statement is correct? --explain the reason in the view of compiler. note: it's not related to initialization or not. say i=2, a=5. I think it is a nice question to test the interviewee's knowledge of compiler.
can you give me a nice explaination?
-
None of them is correct. The first makes no sense, since i++ is not an lvalue, so you may think the second one is correct.
But in the statement ++i = a, i is modified twice between sequence points, so the behavior is undefined. This is all from the language perspective, not sure where the compiler's view enters the picture.edit: Sorry, it seems ++i is not an lvalue either, so both are wrong for the same reason.