Answer
Flashcards · 9645 · AS Topic 1
Procedural programming (AS Level) flashcards
9 cards on AS Topic 1. Pick a subtopic or study them all.
Study mode needs JavaScript. Every card is listed below, so you can still cover the answers and test yourself.
Choose your cards
Session complete
Worth another look:
All 9 cards
For a quick read-through or printing. Cover the right-hand side to test yourself.
Topic 1: Procedural programming
- Procedure vs function
- A procedure carries out a task and returns nothing. A function returns a value.
- Parameter vs argument
- Parameters appear in the subroutine definition. Arguments are the actual values passed when it is called.
- Passing by value vs by reference
- By value: a copy is passed, so the original is unaffected. By reference: the address is passed, so the original can be changed.
- Why prefer local variables and passing by value?
- They prevent side effects, where one subroutine unintentionally alters data another depends on, and make each subroutine independently testable.
- What does a recursive subroutine need?
- A base case that stops the recursion, and a general (recursive) case that moves towards the base case.
- Why can deep recursion cause a stack overflow?
- Each unfinished call is held on the call stack with its own local variables and return address. Too many calls, or no base case, fill the stack.
- Recursion vs iteration
- Recursion is more elegant for tree and divide-and-conquer problems, but uses more memory and is usually slower because of stack overhead. Any recursive algorithm can be rewritten iteratively.
- Syntax vs logic vs runtime errors
- Syntax: breaks the language rules, so the program will not run. Logic: it runs but gives the wrong output, the hardest to find. Runtime: it fails during execution, e.g. division by zero.
- White box vs black box testing
- White box testing tests every path through the code. Black box testing checks inputs against expected outputs without knowledge of the code. Regression testing re-runs earlier tests after a change.