C++ Ch 6 - functions

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

In the following function prototype, how many parameter variables does this function have? int myFunction(double, double, double);

3

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

Select all that apply. Which of the following statement(s) about global variables is(are) TRUE?

A global variable can have the same name as a variable that is declared locally within a function. a global variable is declared in the highest-level block in which it is used

EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called.

EXIT_SUCCESS

A local variable and a global variable may not have the same name within a program. (T/F)

False

Local variables are initialized to zero by default. (T/F)

False

Functions are ideal for menu-driven programs. When the user selects a menu item, the program can ________ the appropriate function.

call

It is good programming practice to ________ your functions by writing comments that describe what they do.

document

Which line in the following program contains a call to 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

When used as parameters, these types of variables allow a function to access the parameter's original argument:

reference

This is a dummy function that is called instead of the actual function it represents:

stub

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


Ensembles d'études connexes

Barron's 800 essential words for the GRE with funny mnemonics, Magoosh GRE Flashcards Common, GregMAT Word List - 1, GregMAT Word List - 21, GregMAT Word List - 20, GregMAT Word List - 19, GregMAT Word List - 18, GregMAT Word List - 16, GregMAT Word...

View Set

Massage Study Guide 1-5 (Petrissage/Contraindicators)

View Set

Chapter 1 Nutrition for Healthy Living

View Set