Cs 1410 Hw7
If a function does NOT have a prototype, default arguments may be specified in the ________.
Function header
t is not considered good programming practice to declare all your variables globally. (T or F)
True
A functions may have the same name as long as their parameter lists are different.
Two or more
What will the following code display? #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
1.) Select all that apply. Which of the following statement(s) about global variables is(are) TRUE? - A global variable is accessible only to the main function - A global variable is declared in the highest-level block in which it is used. - A global variable can have the same names as a variable that is declared locally within a function. - If a function contains a local variable with the same name as the global variable's name takes precedence within the function
- A global variable is declared in the highest-level block in which it is used. - A global variable can have the same names as a variable that is declared locally within a function.
A ________ argument is passed to a parameter when the actual argument is left out of the function.
- Default
When a function is called, flow of control moves to the function's prototype. (T or F)
- False
You must always furnish an argument with a function call. (T or F)
False
You may use the exit() function to terminate a program, regardless of which control mechanism is executing. (T or F)
True
These types of arguments are passed to parameters automatically if no argument is provided in the function call.
- Default
1.) Which line is the following program contains the header for the showDub function? #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; }
- Line 11
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
The value in a ________ variable persists between function calls.
- Static local
This is a dummy function that is called instead of the actual function it represents:
- Stub
Select all that apply. Which of the following must be included in a function header?
- The names of the parameter variables - The names of the function - The data types of each parameter - The data types of the return value
What is the data type of the following function prototype's parameter variable? int myFunction(double);
- double
Which of the following causes a function to execute?
- A function call
A function can have no parameters, one parameters, one parameters and can return _______________ value(s)
only one
Global variables are initialized to zero by default. (T or F)
True
It is possible for a function to have some parameters with default arguments and some without. (T or F)
True
A ________ variable is declared outside all functions.
global
What will the following code display? #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 - 0 - 0
What will the following code display? #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 - 0 - 2
What will the following code display? #include <iostream> Using namespaces std; void showDub(int); int main () { Int x = 2; showDub(x); cout << x << endl; } void showDub(int num) { cout << (num * 2) << endl; }
- 4 - 2
This statement causes a function to end.
- Return
This function causes a program to terminate, regardless of which function or control mechanism is executing.
- exit()
When used as parameters, these types of variables allow a function to access the parameter's original argument:
- reference
Given the following function: 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 segment that invokes calc(): int x = 1 int y =2; int z =3; calc(x,y); cout << x << " " << y << " " << z << endl;
1 6 3
In the following function prototype, how many parameter variables does this function have? int myFunction(double, double, double);
3
EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called.
EXIT_SUCCESS
A function's return data type must be the same as the function's parameter(s). (T/F)
False
A local variable and a global may be not have the same name within the program. (T/F)
False
Local variables are initialized to zero by default. (T or F)
False
Which line in the following program contains a call to the showDub function? #inlude <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; }
Line7
A parameter is a special purpose variable that is declared inside the parentheses of function of a function definition. (T/F)
True
One reason for using functions is to break programs into manageable units or modules. (T or F)
True
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 menu-driven programs. When the user selects a menu item, the program can ________ the appropriate function
call
A function is executed when it is:
called
Given the following header for a function named computeValue, which of the following is a valid call to the function? void computeValue(int value)
computeValue(10);
A function ________ contains the statements that make up the function
definition
It is good programming practice to ________ your functions by writing comments that describe what they do.
document
A collection of statements that performs a specific task is a(n)
function
1.) What is the data type of the following function prototype's return value? int myFunction(double);
int
Which line in the following program contains the prototype showDub function? #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; }
line3
A function ________ eliminates the need to place a function definition before all calls to the function.
prototype
The value in this type of variable persists between function calls
Static
A static variable that is defined within a function is initialized only once, the first time it is called. (T or F)
TRUE