Chapter 6 Flashcards

1
Q

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

A

header

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

definition, prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Values that are sent into a function are called _________.

A

arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

local

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

local

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

________ local variables retain their value between function calls.

A

static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The _________ statement causes a function to end immediately.

A

return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

________ arguments are passed to parameters automatically if no argument is provided in the function call

A

default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A

last

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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

A

constant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

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

A

reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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

A

&

20
Q

Reference variables allow arguments to be passed by _________.

A

reference

21
Q

The _________ function causes a program to terminate.

A

exit

22
Q

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

A

parameter lists

23
Q

Functions should be given names that reflect their purpose.

A

true

24
Q

Function headers are terminated with a semicolon.

A

false

25
Q

Function prototypes are terminated with a semicolon.

A

true

26
Q

If other functions are defined before main, the program still starts executing at
function main

A

true

27
Q

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

A

false

28
Q

Arguments are passed to the function parameters in the order they appear in the
function call

A

true

29
Q

The scope of a parameter is limited to the function which uses i

A

true

30
Q

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

A

false

31
Q

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

A

true

32
Q

Many functions may have local variables with the same name.

A

true

33
Q

Overuse of global variables can lead to problems.

A

true

34
Q

Static local variables are not destroyed when a function returns.

A

true

35
Q

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

A

false

36
Q

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

A

true

37
Q

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 well

A

true

38
Q

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

A

false

39
Q

The exit function can only be called from main.

A

false

40
Q

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

A

true

41
Q

void total(int value1, value2, value3)
{
return value1 + value2 + value3;
}

A

The data type of value2 and value3 must be defined.
The function is declared void but returns a value.

42
Q

double average(int value1, int value2, int value3)
{ double average;
average = value1 + value2 + value3 / 3;
}

A

The assignment statement should read:
average = (value1 + value2 + value3) / 3.0;

43
Q

void area(int length = 30, int width)
{ return length * width
}

A

width should have a default argument value
The function is defined void but returns a value

44
Q

void getValue(int value&)
{ cout &laquo_space;“Enter a value: “;
cin&raquo_space; value&;
}

A

The parameter should be defined as:
int &value
The cin statement should read:
cin&raquo_space; value;

45
Q

(Overloaded functions)
int getValue()
{ int inputValue;
cout &laquo_space;“Enter an integer: “;
cin&raquo_space; inputValue;
return inputValue;
}
double getValue()
{ double inputValue;
cout &laquo_space;“Enter a floating-point number: “;
cin&raquo_space; inputValue;
return inputValue;
}

A

The functions must have different parameter lists.