Based on the possible answers, I suspect that the original
program was
int result = 0, i = 10;
result = ++i + --i;
(note the subtraction has become an addition). As has
been pointed out this invokes undefined behaviour
so there is no "correct answer". However, if the question were
about the program
int result = 0, i = j = 10;
result = ++i + --j;
the question has a correct answer, A. I suspect
that this is the answer that was considered to be
correct.
So your answer is to redefine the question because you can't cope with
the problem and answers as given? You are no longer answering the
question but questioning the question.
As others have pointed out, it is undefined, therefore the proper
answer is: error.
UB means you cannot predict what the result will be because the
standard does not define what implementations are required to do. It
is open to interpretation by the implementation, therefore you cannot
depend on the result from one implementation to another or one version
of an implementation and another.
The implementation in my head says the result should be 11 - 10 in the
original case and 11 + 10 if your redefinition is correct. The
implementation in my head is also inserting a sequence point where
there isn't one under the standard.
Running it in a debugger in VC2010 the answers are 0 and 20, and it is
repeatable for the implementation. Other implementations are free to
compute something entirely different. Again, the results aren't in the
answer set.
For the original, stated problem the Microsoft compiler produces the
disassembly code:
mov eax,dword ptr
add eax,1
mov dword ptr ,eax
mov ecx,dword ptr
sub ecx,1
mov dword ptr ,ecx
mov edx,dword ptr
sub edx,dword ptr
mov dword ptr [result],edx
mov esi,esp
mov eax,dword ptr [result]
push eax
push offset string " Result: %d " (0F9573Ch)
call dword ptr [__imp__printf (0F982B0h)]
and optimizes it as:
push 0
push offset string " Result: %d " (0F420F4h)
call dword ptr [__imp__printf (0F420A0h)]
The puzzle seems to be intended to be a precedence problem where the
tester is seeking to know if the student understands pre-increment and
pre-decrement but the code is erroneous on its face when interpreted
against the current standard.
Why are you redefining the problem? Is it because you can't cope with
the problem statement as written and none of the given answers is
correct under your interpretation of the problem?
When faced with a multiple choice question where one of the answers is
"none of the above" if you need to guess you are probably going to be
correct more often if you choose that one.