\magnification1200
\newif\ifprelim
\prelimtrue
\prelimfalse

\def\\{\char92}
\font\cc=courier at 10pt

\newdimen\hba\hba=\hsize\advance\hba by -60pt

\long\def\hide{\par\setbox0=\vtop\bgroup}
\def\endhide{\egroup\relax%
\par\vrule width 80pt depth .1pt height0pt\par\vskip4pt%
\noindent\unvbox0}

\long\def\hide#1\endhide{}

\def\lb{\char123 }
\def\rb{ \char125}
\def\vr{\char124}
\def\frac#1#2{{{\cc{#1}}\over{\cc{#2}}}}
\newcount\pn\pn=1

\def\newp{%
\ifnum\pn>1 \ifprelim\vskip20pt\else\vfill\eject\fi\fi%
\noindent{\bf \number\pn.}\ \global\advance\pn by1}

\def\code{\vtop\bgroup\bgroup\obeylines\cc\ccode}
\def\ccode#1{#1\egroup\egroup}

\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}}

\centerline{\bf Math 211 Final}
\centerline{\bf May 11, 2001}
\centerline{Professor L.~Taylor}
\vskip20pt
\noindent{\bf Name:\ }$\underline{\hskip4in}$
\bigskip

\newp
Suppose that {\cc cptr} has been declared to be a pointer to a {\cc char}
and also suppose that a {\cc long} takes the same space as {\cc 4} {\cc char}'s.
Explain why the following two statements have the same effect on the value stored in
{\cc cptr}:
\par
{\cc cptr+=4;}
\par
and
\par
{\cc ((long*)cptr)++;}


\newp 
If we solve the second order differential equation 
$$y^{\prime\prime}=y^\prime-y$$
with initial
condition $y(0)=1$ and $y^\prime(0)=2$
via power series method $y=\displaystyle\sum_{n=0}^\infty a_n\,x^n$,
we get
$a_0=1$, $a_1=2$ and
$$a_n=\frac{a_{n-1}}{n}-\frac{a_{n-2}}{n(n-1)}
$$
for $n>1$.
Write a function with declaration
\vskip8pt
\hskip 1in{\cc double coef(short n);}
\vskip8pt
\noindent
which recursively computes $a_n$.
\par\noindent As an example, the statement
{\cc d=coef(3);}
should put $-0.166\cdots$ into {\cc d}.

Be sure to consider what happens if some idiot writes {\cc d=coef(-4);}
and handle it sensibly. (An infinite loop is NOT sensible, but as there is no 
real value to be returned, any return is OK.)
\vskip8pt
\noindent
{\cc double coef(short n)\lb/* Your code here */}



\newp
Suppose we have some function whose code begins with the
following declarations and initializations.

\code{
int  ix=1, iy=2;
int  *ip=\&ix;
}
\bigskip
\item{1.} If the next line reads 

\code{
*ip=iy;
}
what values do both {\cc ix} and {\cc iy} have?
\hide \code{
ix = 2
iy = 2}
\endhide
\bigskip
\item{2.} If {\sl instead\/} of 1. the next line reads 

\code{
iy=*ip;
}
what values do both {\cc ix} and {\cc iy} have?
\hide \code{
ix = 1
iy = 1}
\endhide
\bigskip

\bigskip
\item{3.} If {\sl instead\/} of 1. or 2. the next line reads 

\code{
iy=(*ip)++;
}
what values do both {\cc ix} and {\cc iy} have?
\hide \code{
ix = 2
iy = 1
}
\endhide


\newp
Finally, a multiple choice question!
Given the declarations
{\cc short i, j, k;}
determine which value below is the value of {\cc i} after the following 
statements execute:
{\cc i=k=1; j=2; j*=++k; i=k+j;}
\settabs 5\columns
\+(a) 6 &(b) 5 &(c) 4 &(d) 2 &(e) 1\cr

\noindent
Which value is the value of {\cc j}?

\+(a) 6 &(b) 5 &(c) 4 &(d) 2 &(e) 1\cr
\noindent
Which value is the value of {\cc k}?

\+(a) 6 &(b) 5 &(c) 4 &(d) 2 &(e) 1\cr

%i=1; j=2; k=1;
%j=4; k=2;
%i=6;
\end