questions about TeX expansion

When TeX is expanding tokens and finds a macro, it replaces it with the macro’s replacement text, after having absorbed the arguments, if so specified by the macro. Then it restarts from the first token in the replacement text.

Thus the steps with your code are

\c\a
\b\a
\def\a{2}\a
     <do the assignment>
\a
2

To complement the above description, when TeX finds it has to perform an assignment (here \def), it absorbs the needed tokens, stores the assignment in memory and removes those tokens from the input stream.

Thus \a is not examined until it is the first token in the input stream, unless the order of expansion is modified with \expandafter.

You’d get 1 with

\expandafter\c\a

A further call to \a, would deliver 2.


Expansion is depth first, that is, \c will be completely expanded before \a is expanded, so it will go like this:

\c\a ==>
\b\a ==>
\def\a{2}\a ==>
2