[Tex/LaTex] the difference between \number and \the

macros

I am trying to learn more about macro programming – if that's the right word – in TeX and LaTeX. I began by defining a quantity I called Sum : \newcount\Sum. I then wrote \Sum=0. Then I did some arithmetical operations on Sum, by using \multiply . . . by . . . and \advance . . . by . . ..

Finally I wanted to print out (in the document) the value of Sum. For that I used the line

 The Sum equals **\number**\Sum , 

and it worked as expected ! But later on, I discovered that I might just as well have written

The Sum equals **\the**\Sum ". 

And now I wonder which of the two is the preferred way to write out a numerical value. Are they equivalent ? Or are they intended for different purposes – even if the results overlap in my example ?

Here is an MWE:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Here is the example tex-file that illustrates use of \number and \the .   
%%                                           
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       

\documentclass{article}
\usepackage[paperwidth=4in, paperheight=0.8in]{geometry}

\begin{document}

\newcount\a  \newcount\b  \newcount\Sum

\a=1   \b=5  \Sum=0
\advance\Sum by \a  \multiply\Sum by \b
\advance\Sum by \a  \multiply\Sum by \b

\noindent
The Sum equals \number\Sum  \quad;\quad I used ``number''.
\par \vskip 10pt \noindent
The Sum equals \the\Sum     \quad;\quad I used ``the''.

\end{document}

Best Answer

\number and \the are similar on a count register. \the may be applied to more types, such as

\the\dimen0

or

\the\everypar

or

 \the\font

Using \number on those cases is either an error or (in the first case) casts the dimen to a number, taking its value is sp units.