For clarity I'll denote space tokens by
•, as they are very important in the discussion; spaces in the following code samples should be ignored.
The parameter text of
while the replacement text is
Your call of
Notice that after
\xx there's a space just for delimiting the macro; it is not a space token: it's nothing, because TeX always ignores spaces following control words (not control symbols). The space after
c comes from the end-of-line in your code.
The tokens following
\temp are scanned (without expansion) to find a match with the parameter text, where the argument is delimited by a space, so
#1 ends being
\xx a and the next state of the input stream is
Now TeX performs the definition and removes it from the input stream:
and the part
b•c• is passed to the typesetting stage. After the expansion of the two copies of
\tempii, this is equivalent to having typed
b•c•\xx a\xx a
which is exactly what you got.
If you had used
\? instead of
\xx the last two lines would have been converted into
\? is a control symbol and TeX doesn't ignore spaces after them. In this case the result would be
would produce the same result, because after the action of
\expandafter TeX would be presented with
(same convention for spaces as before, of course). You'd get the same result as with
\? instead of
because then TeX would be presented with
Indeed spaces are ignored after control words only during the tokenization process.