Chapter 6 c++

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

EXIT_SUCCESS

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

All of the above(data types of the parameters, data type of the return value, the name of the function, names of the parameter variables.)

In a function header, you must furnish:

double

Look at the following function prototype. int myFunction(double); What is the data type of the function's parameter variable?

int

Look at the following function prototype. int myFunction(double); What is the data type of the function's return value?

3

Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have?

return

This statement causes a function to end.

local

This type of variable is defined inside a function and is not accessible outside the function.

TRUE

True/False: A parameter is a special-purpose variable that is declared inside the parentheses of a function definition.

TRUE

True/False: A static variable that is defined within a function is initialized only once, the first time the function is called.

TRUE

True/False: Global variables are initialized to zero by default.

TRUE

True/False: It is possible for a function to have some parameters with default arguments and some without.

FALSE

True/False: Local variables are initialized to zero by default.

TRUE

True/False: One reason for using functions is to break programs into manageable units, or modules.

FALSE

True/False: When a function is called, flow of control moves to the function's prototype.

TRUE

True/False: You may use the exit() function to terminate a program, regardless of which control mechanism is executing.

FALSE

True/False: You must furnish an argument with a function call.

2 0 2

WHat is the output? #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; }

7

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; }

2 0 0

What is the output? #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; }

4 2

What is the output? #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; }

reference

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

10

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 }

15

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 }

4

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 }

A global variable can have the same name as a variable that is declared locally within a function.

Which of the following statements is true about global variables?

two or more

_______ functions may have the same name, as long as their parameter lists are different.

TRUE

) True/False: It is not considered good programming practice to declare all of your variables globally.

global

A _____ variable is declared outside all functions.

default

A _______________ argument is passed to a parameter when the actual argument is left out of the function,

prototype

A function ________ eliminates the need to place a function definition before all calls to the function.

argument, parameter

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function.

call

Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can_____the appropriate function.

1 6 3

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;

computeValue (10) ;

Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function?

header

If a function does not have a prototype, default arguments may be specified in the function ________.

Persist

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

document

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

static local

The value in a ________ variable persists between function calls.

static

The value in this type of local variable persists between function calls.

Default

These types of arguments are passed to parameters automatically if no argument is provided in the function call.

exit()

This function causes a program to terminate, regardless of which function or control mechanism is executing.

stub

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

FALSE

True/False: A function's return data type must be the same as the function's parameter(s).

FALSE

True/False: A local variable and a global variable may not have the same name within the same program.

A function ________ contains the statements that make up the function.

definition

Collection of statements that performs a specific task.

function

A function is executed when

it is called

A function can have zero to many parameters, and it can return ________ values.

one

function call

this is a statement that causes a function to execute.


Ensembles d'études connexes

Principles of Management - Chapter 12

View Set

NURS 404: Evolve questions Week 1-2

View Set

Managing Azure Subscriptions and Resources

View Set

Subject Pronouns #1: Write in the subject pronoun in Spanish that is related to the person/people

View Set