Subprograms unit 2 Flashcards

(11 cards)

1
Q

What is a subprogram?

A

A section of code within a larger program that performs a specific task.

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

What is a function?

A

A subprogram that returns a value to the main program.

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

What is a procedure?

A

A subprogram that does not return a value to the main program.

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

What are the benefits of using subprograms?

A
  1. Makes code easier to manage.
  2. Improves reusability.
  3. Makes code easier to read and debug.
  4. Allows for modular design.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a parameter?

A

A value that is passed into a subprogram when it is called.

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

What is the difference between local and global variables?

A

Local variables can only be used inside the subprogram.

Global variables can be used anywhere in the program.

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

Why is using local variables better in subprograms?

A

It prevents accidental changes to data in other parts of the program.

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

What does “passing data into and out of subprograms” mean?

A

Sending input values into the subprogram (parameters) and possibly getting a result back (return value).

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

What is a user-defined subprogram?

A

A function or procedure that you create yourself for a specific task.

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

What is a pre-existing subprogram?

A

A built-in function provided by the programming language (e.g. len(), print() in Python).

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

Example: Define a simple Python function that returns the square of a number.

A

def square(num):
return num * num

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