\magnification1200
\def\\{$\backslash$}
\font\cc=courier at 10pt
\def\lb{$\{$}
\def\rb{$\}$}
\def\vr{$|$}

\newdimen\AA\AA=9pt
\def\boxit#1{\vbox{\hrule\hbox{\vrule\kern3pt
	\vbox{\kern3pt\hbox{\hskip\AA\hbox to 0pt{\hss#1\hss}\hskip\AA%
\vrule width 0pt height10ptdepth4pt}\kern3pt}\kern3pt}\hrule}}

\def\lboxit#1{\vbox{\hrule\hbox{\vrule\kern3pt
	\vbox{\kern3pt\hbox{\hskip\AA\hbox to 0pt{\hss#1\hss}\hskip\AA%
\vrule width 0pt height10ptdepth4pt}\kern3pt}\kern3pt\vrule}\hrule}}

\noindent{\bf 1.}
First consider the declarations.
The declaration {\cc char dd} sets aside a box for a character and we are trying to
figure out what is in that box.
The declaration {\cc char *cc="Aardvark"} sets aside 9 consecutive boxes in memory,

\medskip
\noindent
\hbox{\boxit{{\cc 'A'}}\boxit{{\cc 'a'}}\boxit{{\cc 'r'}}\boxit{{\cc 'd'}}%%
\boxit{{\cc 'v'}}\boxit{{\cc 'a'}}\boxit{{\cc 'r'}}\boxit{{\cc 'k'}}\lboxit{{\cc '\\0'}}}
\medskip
\noindent
and {\cc cc} points to the first box, the one containing the character {\cc 'A'}; {\cc cc+1}
points to the second box, the one containing the character {\cc 'a'}; and so on.

As an aside, {\cc cc+9} points to a very definite location in memory: it points to the
box one after the {\cc \\0}.
We just have no control over what is in that location.
I have met a few compilers for which this box will be the box where {\cc dd} is stored
although most of them put the box for {\cc dd} just before the boxes where {\cc "Aardvark"}
is stored.
For a few more compilers, the {\cc "Aardvark"} will be stored in a special ``strings" area
and will have no relation to the box for {\cc dd} at all.

With this out of the way, consider the statement {\cc dd=*(++cc);}. 
The first thing that happens is that the pointer {\cc cc} is incremented and so now
points to the second box.
Then the value in that box is copied to the {\cc dd} box, so {\cc dd='a'}.
For the other statement {\cc dd=++(*cc);}, the value to which {\cc cc} points 
(i.e. the value in the first box, or the character {\cc 'A'}) is incremented and this value is then 
stored in the {\cc dd} box.
Hence {\cc dd='A'+1='B'}.
A side effect of this incrementation is that the string now reads {\cc "Bardvark"}.

Here are a couple of related comments. 
The statement {\cc dd=(*cc)++;} would take the value pointed to by {\cc cc}, namely {\cc 'A'}
and put it in {\cc dd}, BUT it then increments the value pointed to by {\cc cc} so the string
reads {\cc "Bardvark"}.
Finally, the statement {\cc dd=*(cc++);} does the following: it sets {\cc dd='A'} and then
increments the pointer {\cc cc} so AFTER the statement is finished, {\cc cc} points to
the box containing the {\cc 'a'}.

\bigskip\noindent{\bf 2.}
The declaration {\cc char cc[10]} sets aside ten consecutive boxes in memory,
{\cc cc[0]} through {\cc cc[9]}.
The contents of those boxes are unspecified after the declaration.
The statement {\cc cc[0]='H';} puts the character {\cc 'H'} into the first box and so on.
After all the program before the printf statement is finished, we have a collection of boxes

\medskip
\noindent
\hbox{\boxit{{\cc 'H'}}\boxit{{\cc 'e'}}\boxit{{\cc 'l'}}\boxit{{\cc 'l'}}%%
\boxit{{\cc 'o'}}\boxit{{\sl ?}}\boxit{{\sl ?}}\boxit{{\sl ?}}\boxit{{\sl ?}}\lboxit{{\sl ?}}}
\medskip
\noindent
where {\sl ?}\ indicates a box which has been reserved for us but for which have defined
no value.

The {\cc \%s} inside the format string of the printf statement says to start with the box to
which {\cc cc} points, which happens to have an {\cc 'H'} in it, and print characters until a
{\cc '\\0'} is found. 
The reason for printing what we printed is that the first two {\sl ?}'s above have values
{\cc '8'} and {\cc '\\0'} respectively.
We still do not know what is what values are in the boxes at {\cc cc+7} through {\cc cc+9}.

Notice the {\bf size} of the declaration is irrelevant to this problem.
Once the {\cc \%s} starts, it goes until it finds a {\cc '\\0'} regardless of
how many of those boxes you actually reserved.
To replace the given declaration with {\cc char cc[4];} is definitely an error since then you have 
only reserved 4 spaces but you have used 5 since you do {\cc cc[4]='o';}

One fix is to add the statement {\cc cc[5]='\\0'}. 
This puts a zero at the end of the string.
This is the ``best" fix since now {\cc cc} contains a genuine C string and if expand your
program and use this string elsewhere it should work correctly.

Other possible fixes are
\itemitem{1.} Replace the printf statement with {\cc printf("\%.5s\\n",cc);} which gives you
5 characters or until the {\cc '\\0'}, which ever comes first.
\itemitem{2.} Replace the printf statement with {\cc printf("\%5.5s\\n",cc);} which gives you
5 characters or until the {\cc '\\0'}, which ever comes first and always uses 5 spaces, padding
the leading part with spaces if the {\cc '\\0'} comes before all 5 characters have been used.
\itemitem{3.} Replace the printf statement with {\cc printf("Hello\\n");}.
This answers the last question, if somewhat inelegantly, but of course says nothing to the 
point on the first one.

\bigskip\noindent{\bf 3.}

\hbox{\vtop{\hsize=2in
$$\matrix{%
{\cc x}&1&0&1&1&0&0&1&0\cr
{\cc y}&0&1&1&0&0&1&1&0\cr
\hbox to 0pt{\vrule width 1.8in height .1pt depth0pt\hss}\cr
{\cc\&}&0&0&1&0&0&0&1&0\cr
}$$}
\vtop{\hsize=2in
$$\matrix{%
{\cc x}&1&0&1&1&0&0&1&0\cr
{\cc y}&0&1&1&0&0&1&1&0\cr
\hbox to 0pt{\vrule width 1.8in height .1pt depth0pt\hss}\cr
|&1&1&1&1&0&1&1&0\cr
}$$}}

\hbox{\vtop{\hsize=2in
$$\matrix{%
{\cc x}&1&0&1&1&0&0&1&0\cr
{\cc y}&0&1&1&0&0&1&1&0\cr
\hbox to 0pt{\vrule width 1.8in height .1pt depth0pt\hss}\cr
\hbox{\rm\^{ }}&1&1&0&1&0&1&0&0\cr
}$$}
\vtop{\hsize=2in
$$\matrix{%
{\cc x}&1&0&1&1&0&0&1&0\cr
\hbox to 0pt{\vrule width 1.8in height .1pt depth0pt\hss}\cr
\hbox{\rm\~{ }}&0&1&0&0&1&1&0&1\cr
}$$}}

\bigskip\noindent{\bf 4.}
The first problem is to find a way to determine if an integer such as {\cc 4} or {\cc 100}
does or does not divide {\cc x}.
There are several possible solutions.
The simplest is {\cc x\%4==0}, {\cc x\%4!=0}, {\cc x\%100==0}, etc.
Another possibility is {\cc x==4*(x/4)}, etc.
Two other possibilities are to use the library functions {\cc modf} or {\cc fmod}.
Both of these functions return doubles.
Using {\cc fmod} one can write {\cc fmod(x,4)==0}, etc.
If you want to use {\cc modf} you need to declare a double, say {\cc double xx}.
Then {\cc modf(x/4.0,\&xx)==0}, etc.
The statement {\cc modf(x/4,\&xx)==0}, does not work, because first we compute
{\cc x/4} as an INTEGER, so {\cc modf(x/4,\&xx)} is always {\cc 0}.
If you want to use either {\cc fmod} or {\cc modf} you must remember to include math.h:\ 
{\cc \#include {$<$}math.h{$>$}}

With this problem out of the way, we can write the following code
{{\parindent=0pt\obeylines\cc
char  leap( short x);

char leap( short x) \lb
if( x\%4==0 \&\& x\%100!=0 \vr\vr\ x\%400==0 ) return 1; 
else return 0;
\rb
}}

It would be better to write the test as

\noindent
{\cc ( ( (x\%4==0) \&\& (x\%100!=0) ) \vr\vr\ (x\%400==0) ) }

\noindent
unless you are absolutely sure of the precedence of the various operators.
There is an issue here since {\cc (a \&\& b) \vr\vr\ c $\neq$ a \&\& (b \vr\vr\ c )}.
Of course you can replace the {\cc \%} tests with any of the alternative tests
discussed above and there are other logically equivalent expressions which
may be used.
For example 
{{\parindent=0pt\obeylines\cc
char  leap( short x);

char leap( short x) \lb
if( x\%400==0 return 1; 
else if( x\%100==0) return 0;
else if (x\%4==0) return 1;
else return 0;
\rb
}}

\bigskip\noindent{\bf 5.}
After the first for loop, {\cc zz[0]=0}, {\cc zz[1]=1}, {\cc zz[2]=2}, {\cc zz[3]=3}, etc.
In the second for loop, each {\cc zz[ix]} is computed by taking the current value and adding
the current value of {\cc ix} to it, so we get
 {\cc zz[0]=0+0=0}, {\cc zz[1]=1+1=2}, {\cc zz[2]=2+2=4}, {\cc zz[3]=3+3=6}, etc.
The last for loop is the most confusing to figure out:
to compute {\cc zz[2]} first notice that {\cc zz[2]=zz[9-7]} so {\cc zz[2]=zz[2]-7=4-7=-3}
and {\cc zz[3]=zz[9-6]=zz[3]-6=6-6=0}.

Now consider the format string for the printf statement: {\cc "\%3d\\t\%2d\\n"}:
this will then print a space, then a{\cc '-'}, then a {\cc '3'}, then a tab, then a space, then
a {\cc '0'} and finally a newline.

\end