Chapter 6

¡Supera tus tareas y exámenes ahora con Quizwiz!

Reference variables are defined like regular variables, except there is a(n) _________ in front of the name.

&

Unless you explicitly initialize global variables, they are automatically initialized to _________.

0

Give an example where passing an argument by reference would be useful.

A function such as the following could be written to get user input. The input is stored in the variables that are passed as arguments. void getValues(int &x, int &y) { cout << "Enter a number: "; cin >> x; cout << "Enter another number: "; cin >> y; }

What is the difference between an argument and a parameter variable?

An argument is a value passed to a function. A parameter variable is a variable local to the function which receives the argument. That is to say, the argument's value is copied into the parameter variable.

Why do local variables lose their values between calls to the function in which they are defined?

Because they are created in memory when the function begins execution, and are destroyed when the function ends.

42.T F When a function terminates, it always branches back to main, regardless of where it was called from.

False

It would enable a function to retain a value between function calls. For example, it can keep track of the number of times the function has been called.

How would a static local variable be useful?

If the argument is passed by value, nothing needs to be done. The function cannot access the argument. If the argument is passed by reference, the parameter should be defined with the const key word.

If you are writing a function that accepts an argument and you want to make sure the function cannot change the value of the argument, what do you do?

Where do you define parameter variables?

Inside the parentheses of a function header

What is the advantage of breaking your application's code into several small procedures?

It makes the program easier to manage. Imagine a book that has a thousand pages, but isn't divided into chapters or sections. Trying to find a single topic in the book would be very difficult. Real-world programs can easily have thousands of lines of code, and unless they are modularized, they can be very difficult to modify and maintain.

How do you return a value from a function?

With the return statement. For example, the following statement returns the value in the variable x.

When a function accepts multiple arguments, does it matter in what order the arguments are passed?

Yes. The first argument is passed into the parameter variable that appears first inside the function header's parentheses. Likewise, the second argument is passed into the second parameter, and so on.

Values that are sent into a function are called _________.

arguments

The value of a default argument must be a(n) _________.

constant

_________ arguments are passed to parameters automatically if no argument is pro-vided in the function call.

default

Either a function's _________ or its _________ must precede all calls to the function.

definition, prototype

The _________ function causes a program to terminate.

exit

39.T F Function headers are terminated with a semicolon.

false

45.T F Changes to a function parameter always affect the original argument as well.

false

50.T F All static local variables are initialized to −1 by default.

false

53.T F It is not possible for a function to have some parameters with default arguments and some without.

false

54.T F The exit function can only be called from main.

false

_________ variables are defined outside all functions and are accessible to any function within their scope.

global

_________ variables provide an easy way to share large amounts of data among all the functions in a program.

global

The _________ is the part of a function definition that shows the function name, return type, and parameter list.

header

When a function uses a mixture of parameters with and without default arguments, the parameters with default arguments must be defined _________.

last

A(n) _________ variable is defined inside a function and is not accessible outside the function.

local

If a function has a local variable with the same name as a global variable, only the _________ variable can be seen by the function.

local

Two or more functions may have the same name, as long as their _________ are different.

parameter lists

Special variables that hold copies of function arguments are called _________.

parameters

A(n) _________ eliminates the need to place a function definition before all calls to the function.

prototype

Reference variables allow arguments to be passed by ____________.

reference

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

reference

The _________ statement causes a function to end immediately.

return

_________ local variables retain their value between function calls.

static

38.T F Functions should be given names that reflect their purpose.

true

40.T F Function prototypes are terminated with a semicolon.

true

41.T F If other functions are defined before main, the program still starts executing at function main.

true

43.T F Arguments are passed to the function parameters in the order they appear in the function call.

true

44.T F The scope of a parameter is limited to the function that uses it.

true

46.T F In a function prototype, the names of the parameter variables may be left out.

true

47.T F Many functions may have local variables with the same name.

true

48.T F Overuse of global variables can lead to problems.

true

49.T F Static local variables are not destroyed when a function returns.

true

51.T F Initialization of static local variables only happens once, regardless of how many times the function in which they are defined is called

true

52.T F When a function with default arguments is called and an argument is left out, all arguments that come after it must be left out as wel

true

55. T F A stub is a dummy function that is called instead of the actual function it represents.

true

When only a copy of an argument is passed to a function, it is said to be passed by _________.

value

If a function doesn't return a value, the word _________ will appear as its return type.

void


Conjuntos de estudio relacionados

Chapter 46: Drugs for Diabetes Mellitus

View Set

unit 4 chapter 13 — public opinion

View Set

3rd attempt on the guaranteed exam

View Set