c - Undefined expression with a definite answer? -
i'm trying understand answer interview question.
the following code presented:
int x = 5; int y = x++ * ++x; value of y? the answers presented list of multiple choice answers, 1 of them being 35.
writing , running code on machine results in y being equal 35.
therefore expect mark answer question 35.
however, isn't expression undefined due x++ i.e. side of effect (the actual incrementation of x) happen @ time depending on how compile chooses compile code.
therefore, not have thought the answer 35 different compilers might produce difference results.
another possible multiple choice answer 30, have thought viable i.e. if post increment side effect takes place towards end of sequence point.
i don't have answer key, it's hard determine best answer give.
is poor question or answer more obvious?
you correct; standard not impose requirements @ on code might do.
if multiple-choice question required choose specific defined answer, — whoever wrote question doesn't understand c do. keep in mind when decide whether accept offer there. :-)
Comments
Post a Comment