\input{/home/fac/samal/class/tex/classmacros.tex}
\textheight=9.75in
\topmargin=-.5in
\parindent=0.0in

\begin{document}
\pagestyle{empty}
\handout{CS 156 : Intro. to Computer Science II}{Pre Test / Quiz No. 1}{January 13, 1999}

Select the {\em most appropriate} answer for each of the following questions. 
Then enter the choice in the table at the end (Page 2).


\begin{enumerate}

\item What does the following code fragment output at the end
if the value of {\tt x} before 
the while loop is $20$?

\begin{verbatim}
while (x) {
    cout << x;	
    x -= 5;
}
\end{verbatim}

\begin{tabular}{lll}
{\bf (a).} 0 & {\bf (b).} -1 & {\bf (c).} 20\\
{\bf (d).} 25 & {\bf (e).} 5 & {\bf (f).} None of the above.\\
\end{tabular}

    \item What does the above code fragment do if the value of {\tt x} before 
the while loop is $21$?

\begin{tabular}{lll}
{\bf (a).} 0 & {\bf (b).} -1 & {\bf (c).} 20\\
{\bf (d).} 25 & {\bf (e).} 5 & {\bf (f).} None of the above.\\
\end{tabular}


\item What is the output when the following is executed?
\begin{verbatim}
int f (int &x)
{    
    x = x+2;    
    return x; 
}
void main()
{
    int i=2, j=f(i);
    j *=f(i);    cout << j;
}
\end{verbatim} 
\begin{tabular}{lll}
{\bf (a).}24 & {\bf (b).}10 & {\bf (c).}8\\
{\bf (d).}16 & {\bf (e).}4 & {\bf (f).} Improper function call\\
\end{tabular}


\newpage
\item Which of the following declares an array of size 5?

\begin{tabular}{lll}
{\bf (a).}a5[int 5]; & {\bf (b).} int a5[int 4] & {\bf (c).}int a4[int 5]\\
{\bf (d).}int a4[4]; & {\bf (e).}int a4[5]; & {\bf (f).}f. int N = 5; int a[N]\\
\end{tabular}

\item What is the value of i after the following is executed?
\begin{verbatim}
int plus2(int i)
{ 
    i = 2+i; 
    return i;
}
void main()
{
    int u, i=0;    u = plus2(i);    i++;
}
\end{verbatim}
\begin{tabular}{lll}
{\bf (a).} 2 & {\bf (b).} 1 & {\bf (c).} 3\\
{\bf (d).} 0 & {\bf (e).} -1 & {\bf (f).}None of the above.\\
\end{tabular}


 \item Suppose the body of a function definition is

\begin{verbatim}
{
    int temp = x;
    x = y;    y=temp;     return x;
}
\end{verbatim}
and suppose the first line of this function definition is one of the
following:
\begin{enumerate}
\item  void swap(int x, int y)
\item  int swap(int x, int y);
\item  int swap(int \&x, int y);
\item  void swap(int \&x, int \&y);
\item  int swap(int \&x, int \&y);
\end{enumerate}

Which of the function definitions (first line with the body above) gives a
function that swaps its actual parameters?\\
\begin{tabular}{lll}
{\bf (a).} (1) and (5)& {\bf (b).}(4) and (5) & {\bf (c).}(4) only \\
{\bf (d).} (3) and (5) & {\bf (e).} (5) only & {\bf (f).}  None of the above.\\
\end{tabular}

\end{enumerate}
\LARGE
\vspace*{0.35in}
\begin{center}
\begin{tabular}{|l|l|l|l|l|l|}\hline
1 & 2 & 3 & 4 & 5 & 6  \\\hline
 & & & & &    \\\hline
\end{tabular}
\end{center}
\vspace*{0.5in}


\end{document}


