Name_______________________
Login___________________SID________
CS 010: Introduction to
Computer Science I
Quiz 5: 10 minutes
Use
the following function headers for the next 4 questions
void func1(int num1, int& num2)
int func2(string str, int num)
- Which
statement(s) has an error?
func1(10,
5); //Statement 1
cout <<
func2(“abc”, 20); //Statement 2
a.
Statement
1
b.
Statement 2
c.
Statements 1 and 2
d.
No errors in either statement
- Which
statement(s) has an error provided n1 and n2 are int variables that have
been declared and initialized?
cout <<
func1(n1, n2); //Statement 1
cout <<
func2(“abc”, n1); //Statement 2
a.
Statement
1
b.
Statement 2
c.
Statements 1 and 2
d.
No errors in either statement
- Which
statement(s) has an error provided n1 and n2 are int variables that have
been declared and initializes?
func1(10, n1); //Statement 1
cout <<
func2(10, “abc”); //Statement 2
a.
Statement 1
b.
Statement
2
c.
Statements 1 and 2
d.
No errors in either statement
- Which
statement(s) has an error provided n1 is an int variable that has been
declared and initialized?
func1(func2(“abc”, 20), n1);
cout << func2(“abc”,
func1(10, n1));
a.
Statement 1
b.
Statement
2
c.
Statements 1 and 2
d.
No errors in either statement
- Out
of the following function headers, which is the BEST choice
for a function that just reads in 2 integers from the user and “passes”
them back to where the function was invoked (called)?
- void get_inputs(int&
input1, int& input2)
- void
get_inputs(int input1, int input2)
- int
get_inputs(int input1, int input2)
- int
get_inputs(int& input1, int& input2)
- int
get_inputs()
- void
get_inputs()
- Out
of the following function headers, which is the BEST choice
for a function that returns the value of the largest of 2 integers passed
in as parameters?
- void
max(int& first, int& second)
- void
max(int first, int second)
- int max(int first, int
second)
- int
max(int& first, int& second)
- int
max()
- void
max()
- It
is a syntax error to have a return statement in a void function (a
function that has the return type of void).
- TRUE
- FALSE
Use the following function definitions to answer the next 3
questions
void func1(int& x)
{
x += 50;
return;
}
int func2(int y)
{
y += 50;
func1(y);
return y;
}
- What
is output by the following statements?
int a = 50;
func1(a);
cout << a;
- 0
- 50
- 100
- 150
- There
is a syntax error in these statements
- None
of the above
- What
is output by the following statements?
int a = 50;
int b = func2(a);
cout << a << “ “
<< b;
- 50 150
- 100
100
- 50
100
- 150
150
- There
is a syntax error in these statements
- None
of the above
- What is output by the following
statement?
cout << func2(50);
- 0
- 50
- 100
- 150
- There
is a syntax error in this statement
- None
of the above