7. Functions Flashcards

1
Q

What is a function?

A

A block of code that can be called by other statements.

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

Describe the parts that can be used when defining a function

A

Return type,
Function name,
( ) containing zero or more parameters (return type plus parameter name) separated by commas, and
{ } containing one or more statements for the body of the function, and optionally a return type.

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

How do you call or invoke a function?

A

Code the name of the function and a set of parentheses.

Within the parentheses, code one or more arguments in the same order as the parameters in the function definition.

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

What does the void return type mean?

A

The function does not return any data.

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

What is the relation between the return type and the return statement?

A

The return statement must return data of the return type.

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

Identify best practice for naming functions

A

Start the name with a verb,
can follow verb with a noun or adjective plus a noun,
name should reasonably describe purpose of function.

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

Identify best practice for naming functions

A

Start the name with a verb,
can follow verb with a noun or adjective plus a noun,
name should reasonably describe purpose of function.

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

How do you declare a function without its definition?

A

Code the function’s return type, name, and optionally the parameters, followed by a semicolon.

Though optional, including the parameters improve readability of the code.

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

What do you call a function that has been declared but not defined?

A

function prototype

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

What is a local variable?

A

A variable defined inside a function.

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

What is a global variable?

A

A variable defined outside of all functions.

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

Where can a local variable be used?

A

Only within the function that defines it.

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

What is a shadow variable?

A

When a local variable has the same name as a global variable.

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

What happens to variable operations if you have a shadow variable?

A

In a function that defines the variable, all operations are done on the local variable.

Otherwise, all operations are done on the global variable.

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