Programming Elements and Constructs Flashcards

1
Q

Subroutines Definition

A

A sequence of program instructions that performs a specific task, packaged as a unit

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

Parameters Definition

A

Pieces of data that are passed into a subroutine in order for that subroutine to correctly function

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

Why do we use subroutines?

A
  • Avoid repetition (This reduces size of program, makes code easier to maintain, and removes possibility that some code is updated while others are not)
  • Define a logical structure for the program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Advantages of subroutines

A
  • Breaks down complex programs to make it easier to solve
  • Can be used several times within a program
  • Can reduce the amount of code than needs to be written as it allows reusing of codes without having to write it again
  • Divides large program into small portions to enable simultaneous work
  • Easier to read with sensible subroutine labels
  • Reducing the amount of repeated task lowers the risk of errors
    Easy to maintain as each subroutine can be tested separately
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Local vs Global Variables?

A
  • Local can only be accessed within the subroutine while global can be accessed by any subroutine
  • Local is declared within a subroutine while global is declared outside
How well did you know this?
1
Not at all
2
3
4
5
Perfectly