Cs135- Chapter 6 quiz
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? int x = 1; int y = 2; int 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 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 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 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 0 0
What is the output of the following program? #include 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 0 2
What is the output of the following program? #include 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 of the return value b. the name of function c. names of parameter variables d. data type(s) of the parameters all are correct thats why all are listed
A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function.
argument, parameter
Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function.
call
A function is executed when it is:
called
A function ________ contains the statements that make up the function.
definition
It is a good programming practice to ________ your functions by writing comments that describe what they do.
document
Look at the following function prototype. int myFunction(double); What is the data type of the function's parameter variable?
double
Look at the following function prototype. int myFunction(double); What is the data type of the function's return value?
int
This type of variable is defined inside a function and is not accessible outside the function.
local
A function can have zero to many parameters, and it can return this many values.
only one
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