User Defined Functions Flashcards

1
Q

What is a subprogram?

A

Groups of code that break large programs down into smaller parts. In processing, these are called functions (methods in Java and C#)

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

What do functions allow programmers to do?

A
  • write a large program piece by piece
  • many programmers can work on separate parts of the program
  • standard libraries of subprograms can be used by many people
  • functions with parameters allow variation in the function outcome
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are functions?

A

Blocks of code which encapsulate some task into a black box or module

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

What things make up all functions?

A
  • a name
  • some data items they accept, with specific types (parameters)
  • a type of data item that they give back as a result (or void)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the signature of the function?

A

The name and the types
eg. float getPercent(int, int)

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

What happens of values passed in as parameters?

A

They are copied and stored in the function’s local variable.

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

What happens if the you change the value of the local variable in the function?

A

The values passed will not change

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

What happens to local variables after a function is finished executing?

A

They disappear

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

How many return types can a function have?

A

one or none

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

What happens when the return statement is executed?

A

The function is exited and optionally returns the value from it.

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

Are return statements required?

A

If the return type is not void, then yes. Otherwise, they are optional. It is best practice to only have one return statement

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

What happens when you pass a String into a function?

A

The address stored in the original String variable is copied into the local variable. This means that any changes made to the String will be reflected outside of the function

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

What is the header?

A

The first line of code of an actual function definition. Unlike the signature, which is an abstraction of the header and is only used to match function calls to functions

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

What is function overloading?

A

Defining multiple functions with the same name but different parameter lists (two functions with the same name must have different signatures)

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

Can you use variables of the same name outside of a function?

A

Yes. Parameters and variables defined in a function become local to that function

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

What are stand-alone functions?

A

Functions that don’t change globals. All data comes in through parameters and goes out through return. These are good because you don’t have to worry about side-effects

17
Q

What are function side-effects?

A

Usually when a function changes non-final global variables, it might have some unexpected outcomes