Chapter 6 Computer Science Quiz-AB
Given the following function definition void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code fragment that invokes calc? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;
1 6 3
Which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }
10
Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }
15
What is the output of the following program? #include <iostream> using namespace std; void doSomething(int&); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int& num) { num = 0; cout << num << endl; }
2 2 2
Which line in the following program contains the prototype for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }
4
What is the output of the following program? #include <iostream> using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; }
4 2
What is the output of the following program? #include <iostream> using namespace std; int getValue(int); int main() { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5; }
7
In a function header, you must furnish: A)data type(s) of the parameters B)data type of the return value C)the name of function D)names of parameter variables E)All of these
E)All of these
A function's return data type must be the same as the function's parameter(s).
False
T/F: When a function is called, flow of control moves to the function's prototype.
False
T/F: You must furnish an argument with a function call.
False
What is the output of the following program? #include <iostream> using namespace std; void doSomething(int); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num) { num = 0; cout << num << endl; }
The answer is NOT 2 0 0 It is probably 2 0 2
A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.
True
T/F: It is not considered good programming practice to declare all of your variables globally.
True
T/F: One reason for using functions is to break programs into manageable units, or modules.
True
________ functions may have the same name, as long as their parameter lists are different.
Two or more
Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function?
computeValue(10);
Look at the following function prototype. int myFunction(double); What is the data type of the funtion's parameter variable?
double
This is a collection of statements that performs a specific task.
function
This is a statement that causes a function to execute.
function call
A ________ variable is declared outside all functions.
global
Look at the following function prototype. int myFunction(double); What is the data type of the funtion's return value?
int
This type of variable is defined inside a function and is not accessible outside the function.
local
If a function is called more than once in a program, the values stored in the function's local variables do not ________ between function calls.
persist
A function ________ eliminates the need to place a function definition before all calls to the function.
prototype
When used as parameters, these types of variables allow a function to access the parameter's original argument.
reference
This statement causes a function to end.
return
The value in this type of local variable persists between function calls.
static
The value in a(n) ________ variable persists between function calls.
static local