c Flashcards

(49 cards)

1
Q

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

A

A: Because they are created when the function starts and destroyed when it ends.

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

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

A

A: An argument is the value sent to a function; a parameter is the variable that receives it.

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

Q: Where do you define parameter variables?

A

A: Inside the parentheses of a function definition.

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

Q: If you want a function to not change the value of the argument it receives what should you do?

A

A: Pass it by value (not by reference) or use the const keyword if using reference.

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

Q: When a function accepts multiple arguments does the order matter?

A

A: Yes the order must match the parameters’ order in the function definition.

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

Q: How do you return a value from a function?

A

A: Use the return statement followed by the value.

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

Q: What is the advantage of breaking your application’s code into small procedures?

A

A: It makes the code easier to read reuse

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

Q: How would a local variable be useful?

A

A: It keeps data private to the function and avoids affecting other parts of the program.

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

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

A

A: Updating multiple values in a function like a function that modifies two numbers.

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

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

A

function header

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
Q

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

A

prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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
14
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
15
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
16
Q

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

A

function prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
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
18
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
19
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
20
Q

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

21
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.

22
Q

_________ local variables retain their value between function calls.

23
Q

The _________ statement causes a function to end immediately.

24
Q

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

25
When a function uses a mixture of parameters with and without default arguments, the parameters with default arguments must be defined _________.
last
26
The value of a default argument must be a(n) _________.
constant
27
When used as parameters, _________ variables allow a function to access the parameter’s original argument.
reference
28
Reference variables are defined like regular variables, except there is a(n) _________ in front of the name.
ampersand (&)
29
Reference variables allow arguments to be passed by ____________.
reference
30
The _________ function causes a program to terminate.
exit
31
Two or more functions may have the same name, as long as their _________ are different.
parameter lists (signature)
32
Functions should be given names that reflect their purpose.
True
33
Function headers are terminated with a semicolon.
False
34
Function prototypes are terminated with a semicolon.
True
35
If other functions are defined before main, the program still starts executing at main.
True
36
When a function terminates, it always branches back to main, regardless of where it was called from.
False
37
Arguments are passed to the function parameters in the order they appear in the function call.
True
38
The scope of a parameter is limited to the function that uses it.
True
39
Changes to a function parameter always affect the original argument as well.
False
40
In a function prototype, the names of the parameter variables may be left out.
True
41
Many functions may have local variables with the same name.
True
42
Overuse of global variables can lead to problems.
True
43
Static local variables are not destroyed when a function returns.
True
44
All static local variables are initialized to −1 by default.
False
45
Initialization of static local variables only happens once, regardless of how many times the function is called.
True
46
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.
True
47
It is not possible for a function to have some parameters with default arguments and some without.
False
48
The exit function can only be called from main.
False
49
A stub is a dummy function that is called instead of the actual function it represents.
True