Section 11: Programming techniques Flashcards

1
Q

What is passing a parameter by value?

A

If a parameter is passed by value, its actual value is passed through the subroutine where it is treated as a local variable. Therefore, if you change the parameter inside the subroutine its value in the main program will not change.

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

What is passing a parameter by reference?

A

If a parameter is passed by reference, its address is passed through the subroutine so that when the variable is written to inside the subroutine, it is also written to inside the main program.

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

What are the advantages of modular programming?

A

Advantages of modular programming:

  • Easier to find errors
  • Subroutines can be tested independently, which shortens the time to get a big program working
  • Once a subroutine has been tested you can re-use it throughout the program
  • Easier for a team of programmers to work on
  • Makes code neater and easier for other programmers to read
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 3 essential characteristics of recursion?

A

3 essential characteristics of recursion:

  • Must include a stopping condition or base case
  • Routine must call itself for input values other than the stopping condition
  • Stopping condition must be reached after a finite number of calls
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is encapsulation important?

A

Encapsulation is important because it allows the developer to test a subroutine independently and use it in many different programs without having to know what variables it uses. Also, it stops there being conflict where two variables may coincidentally have the same name in a program.

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

How is the call stack used when calling a subroutine?

A

Each time a subroutine is called, the address, parameters and local variables used are held in a stack frame in the call stack, which then subsequently unwinds once the end of the subroutine is reached.

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