COSC 1336 Chapter 6 Functions Quiz
What will the following code display? #include <iostream> using namespace std; void doSomething(int); int main() { int x = 2; cout << x << " "; doSomething(x); cout << x << " "; return 0; } void doSomething(int num) { num = 0; cout << num << " "; }
2 0 2
In the following function prototype, how many parameter variables does this function have? int myFunction(double x, double y, double z);
3
What will the following code display? #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) <<" "; }
4 2
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
A function __________ contains the statements that make up the function.
definition
What is the data type of the following function prototype's return value? int myFunction(double);
int
Given the following function, what would be an appropriate call to this function? #include "pch.h" #include <string> #include <iostream> using namespace std; int myFunction(int x, int y, string z);
int a = myFunction(1, 2, "3");
Which line in the following program contains the header for the showDub function? 1 #include <iostream> 2 using namespace std; 3 void showDub(int); 4 int main() 5 { 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub(int num) 12 { 13 cout << (num * 2) << endl; 14 }
line 11
Which line in the following program contains the prototype showDub function? 1 #include <iostream> 2 using namespace std; 3 void showDub(int); 4 int main() 5 { 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub(int num) 12 { 13 cout << (num * 2) << endl; 14 }
line 3
Which line in the following program contains the call for the showDub function? 1 #include <iostream> 2 using namespace std; 3 void showDub(int); 4 int main() 5 { 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 void showDub(int num) 12 { 13 cout << (num * 2) << endl; 14 }
line 7
This type of variable is defined inside a function and is not accessible outside the function.
local
A function can have no parameters, one parameter, or many parameters and can return __________ value(s).
only one
A function _________ eliminates the need to place a function definition before all calls to the function.
prototype
This statement causes a function to end.
return