\magnification1200
\footline{}
\newbox\arrowtmp
\newbox\arrowtmpA
\newdimen\arrowwd
\def\limitsarrow#1#2#3{%
\setbox\arrowtmp=\hbox{$\scriptstyle11#1$}%
\setbox\arrowtmpA=\hbox{$\scriptstyle11#2$}%
\ifdim\wd\arrowtmp<\wd\arrowtmpA\relax
\arrowwd=\wd\arrowtmpA\relax\else%
\arrowwd=\wd\arrowtmp\relax\fi%
\smash{\mathop{\vbox to 3pt{\vss\hbox to \arrowwd{#3}}}\limits^{#1}\limits_{#2}}%
}

\def\cy#1{\Z/{#1}\Z}
\def\RA#1{\limitsarrow{#1}{}{\rightarrowfill}}
\centerline{\bf Math 211 Final}
\centerline{\bf May 8, 1998}
\centerline{Professor L.~Taylor}

\def\boxit#1{\vbox{\hrule\hbox{\vrule\kern3pt
	\vbox{\kern3pt#1\kern3pt}\kern3pt\vrule}\hrule}}

\newcount\pc\pc=1
\def\nl{\medskip\noindent}
\def\np{\nl{\bf Problem \number\pc.\ }\global\advance\pc by 1}
\def\Z{{\bf Z}}
\def\C{{\bf C}}
\bigskip
\np
A program with the standard main declaration
\def\lb{$\{$}
\def\rb{$\}$}

\bigskip\noindent
{\tt main(int argc, char *argv[]) \lb

$\vdots$

\rb}

\bigskip\noindent
was compiled to produce {\tt a.out}.
The program was run with command line

\medskip
\noindent{\tt a.out -kim 1 5.0 aardvark}
\medskip

\noindent
What was in {\tt argv[3]}?
More explicitly, suppose the boxes below represent a collection
of consecutive bytes of memory in the computer and that {\tt argv[3]}
points to the box with the arrow above it.
Fill in the remaining boxes.
Put a question mark (?) in any box whose contents are unknown given the
data.
Put your final answer in the top row of boxes, but you may use the lower
row to experiment before committing yourself.

\bigskip
\dimen0=20 true pt\dimen1=10 true pt
\setbox0=\vtop to\dimen0{\hbox to\dimen0{\hfill}\vfil}
\def\xx{\boxit{\copy0}\hskip\dimen1}

\noindent\hskip73pt{$\downarrow$}

\noindent\hbox{\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx%
}
\vskip40pt
\noindent\hbox{\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx\xx%
}

\let\NP=\np
\def\np{\vfill\eject\NP}
\np
Suppose you are working in a programming language which has an
``if'' statement with the following syntax:

\bigskip
\noindent{\tt if[ test, false-expression, true-expression]}
\bigskip
\noindent
where {\tt test} is an expression which evaluates {\tt true} or {\tt false}.
If {\tt test} is {\tt true} we do the {\tt true-expression}, otherwise we do the
{\tt false-expression}.
Suppose we have the following problem.
We have two tests, {\tt test1} and {\tt test2} and three expressions, {\tt exp1},
{\tt exp2} and {\tt exp3}.
How would we write an ``else if'' expression in this language?
Explicitly, write an expression which will do {\tt exp1} if {\tt test1} is true
and will do {\tt exp2} if {\tt test1} is false but {\tt test2} is true and will
do {\tt exp3} if both tests are false.

\vfill
\np
Here is a very short program.

\noindent{{\obeylines\tt
main()
\lb
        short   i;
i=12;
printf("\%d$\backslash$n",\&i);
\rb
}}

\bigskip
\noindent
I compiled it and ran the {\tt a.out} and
got the answer 
\medskip
-268437934
\medskip\noindent
What's going on?
Address two points in your answer.
Why didn't I get 12 and what is -268437934?

\np
C has several pitfalls, among them being that unspecified details are 
left to the people writing the compiler and many people feel that C
does not specify enough. 
An example of ``compiler dependence'' is that the order of evaluation
of the arguments of a function are unspecified: the compiler may
do them in any order it chooses.
This leads to mistakes when trying to be clever.
As an example, suppose 
\medskip\noindent
{\tt short ff(short, short);}
\medskip\noindent
 is a declaration and suppose
{\tt ix {\rm and} iy} are shorts.
Suppose {\tt ix} has the value 5 when the line.
\medskip\noindent{\tt iy=ff(ix++,ix);}
\medskip
\noindent is encountered.
After this line {\tt ix} is 6, but {\tt iy} will be
{\tt ff(5,5)} if the second expression is evaluated first
or else {\tt ff(5,6)} if the first expression is evaluated first.
This leads to programs which work correctly when compiled with one
compiler but work wrong when compiled with another.
Discuss the various possibilities for
\medskip\noindent{\tt iy=ff(ix++,--ix);}
\medskip
\noindent assuming that {\tt ix} has the value 7.
\medskip
\itemitem{(a)} If the first expression is evaluated first, 
\vskip 1true in\vfill
\itemitem{(b)} If the second expression is evaluated first,


\np
Recall Pascal's triangle for evaluating binomial coefficients.
It $n\choose k$ is defined to make the binomial theorem work,
$$(x+y)^n=\sum_{k=0}^n{n\choose k}x^ky^{n-k}$$
for positive integers $n$. 
Inductively, 
${n\choose0}={n\choose n}=1$; ${n\choose1}={n\choose n-1}=n$
and ${n\choose k}={n-1\choose k}+{n-1\choose k-1}$ for
$1<k<n-1$.
Given the declaration
\medskip\noindent{\tt
long	comb(short n, short k);}
\medskip\noindent
write code for {\tt comb} so that {\tt comb(n,k)} recursively calculates $n\choose k$.

\bigskip\noindent{\tt
long	comb(short n, short k) \lb /* Your code here */}




\end
