Name_______________________
Login___________________SID________
CS 010: Introduction to
Computer Science I
Quiz 6: 10 minutes
Use the following function headers
for the next 4 questions.
void
func1(int x)
void
func2(int &x)
Assuming there is an integer
called num, are the following statements valid?
- func2(25);
- TRUE
- FALSE
- func1(num*20+3);
- TRUE
- FALSE
- func1(rand()%100+1);
- TRUE
- FALSE
- func2(num);
- TRUE
- FALSE
Specify the best passing technique for the following
parameters.
- double
x = slope(myline);
- Pass-by-value
- Pass-by-reference
- scale_rectangle(length,
width, scale_amount); //
Specify for the parameter length
- Pass-by-value
- Pass-by-reference
- change_name(boss);
- Pass-by-value
- Pass-by-reference
- Which
of the following statements is NOT true?
- A
non-void function must have a return statement.
- The return statement
resumes execution in the main program.
- A
function can have more than one return statement.
- It
is legal to omit the return statement in a void function.
- Functions
can only return one value.
Use the code below for the next 2 questions.
void f1(int &x)
{
x
= 100;
}
void f2(int &a, int b)
{
a
= a * b;
b
= 12;
if
(b < a)
{
f1(b);
}
else
{
f1(a);
}
}
int main()
{
int num1 = 2;
int num2 = 4;
f2(num1, num2);
cout <<
num1 << “ “ << num2 <<
endl; // OUTPUT 1
num1 = 4;
num2
= 5;
f2(num1,
num2);
cout
<< num1 << “ “ << num2 << endl; // OUTPUT 2
return
0;
}
- What
will OUTPUT 1 print?
- 2 4
- 100 4
- 8
12
- 100 12
- None
of the above
- What
will OUTPUT 2 print?
- 20 5
- 20 100
- 4 5
- 20 12
- None
of the above