Lecture 12 Flashcards

1
Q

What is “passing in” a parameter?

A

Transferring in a value from the calling side to a function.

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

What 3 things should you consider when creating function names?

A

Descriptive, memorable, and consistent names

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

What is a function?

A

A program consisting of various instructions that can have input parameters/arguments, takes some action, and possibly returns a value and can be called.

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

What are parameters?

A

Parameters are the values that go in a function header. The functions parameters match up one-to-one with the arguments in a function call.

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

What are arguments?

A

Arguments are the values placed in parentheses when a function call is made.

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

What is a return value?

A

The value sent back to the part of the function that called the program.

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

What is a function header?

A

Everything that is needed for the function to interact with the larger program.

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

What is the function body?

A

Set of instructions for the function that you want to follow when the function is called.

*enclosed in curly braces after function header**

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

What are global variables?

A

Variables that exist throughout the entire program, including functions.

typically declared at the beginning of a program

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

What are local variables?

A

Variables that only exist within the function they are defined in.

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

What are the two main reasons to use functions?

A
  1. Functions offer conceptual separation of ideas/the ability to write code without worrying about details.
  2. Using functions allows you to avoid writing the same code over and over.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is included in a function header?

A
  1. Return type
  2. Function name
  3. Parameter type(s) and name(s) in parentheses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the type for a function that does not return anything?

A

Void

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

Where should a function definition occur in a program?

A

Before it is called. Typically, functions are defined near the beginning of a file.

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

How would you exit a function with no return value?

A

Write the return command with no value
or
use void as the return type in the header and not use the return command. The function will end when the code ends.

E.g. return;

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

What is another way you can exit a function that returns a void type?

A

Leave off the return command–the function will end when the function body ends.

17
Q

What is scope?

A

The range of a program in which a variable is defined.

18
Q

What are global variables?

A

Variables that are in scope for the entire program and in every function.

19
Q

Explain functions.

A

Functions are a pre-made piece of code that can be used at any point in your program by typing the function name and any arguments.