2.2.1 Programming techniques Flashcards
2.2.1 A)
What’s a programming construct used for.
used to represent control flow structured programming
2.2.1 A)
What are the 3 programming constructs.
Sequence , branching/selection , iteration
2.2.1 A)
What is a sequence in term of programming constructs.
Code is executed line by line top to bottom
2.2.1 A)
What is branching / selection in term of programming constructs.
Code is run if a specific condition is met (if statement)
2.2.1 A)
What is iteration in term of programming constructs.
Code is executed certain number of times or while a condition is met. (for/while statement)
2.2.1 B) What is recursion
A construct in which a subroutine calls apron itself during execution. This continues until a certain condition is met ( stopping condition ).
2.2.1 B)
What is recursion like and how is it different.
produces the same result as iteration but suited to certain problems.
2.2.1 B)
What’s the advantage of recursion.
CAN be represented in fewer lines which can lead to less errors. But it needs to be clearly defined to reach a stopping condition
2.2.1 B)
How do stacks work in recursion.
Every time the stack calls itself a new stack frame is created within the stack. Stack frames are created until stopping condition is met and subroutine unwinds. Information from the call stack being popped off the stack.
2.2.1 B)
What is recursion used for?
For storing parameters, local variables and return addresses are stored allowing the subroutine to return to a particular point during execution.
2.2.1 B)
What’s the disadvantage of recursion
inefficient use of memory, danger of stack overflow (if it calls it self too many times call stack runs out of memory) this can lead to the program crashing, Difficult to trace.
2.2.1 B)
How can recursion be improved ?
can use tail recursion its a form of recursion which implemented in a more eff way, less stack space is needed
2.2.1 C)
What is scope
refers to the section of code the variable is available too.
2.2.1 C)
What is a local variable
It has a limited scope, only can be accessed within a block of code in which they were defined.
2.2.1 C)
Adv of local variable
multiple local variables can have same name not effect each other. good practice ensures subroutines are self contained.
2.2.1 C)
What is a global variable
can be accessed across whole program its declared outside of a subroutine
2.2.1 C)
dis(adv) of global variable
useful for values used by multiple parts of program
can be unintentionally overwritten / edited
2.2.1 C)
When are global / local variables deleted.
Global variables deleted after the program finishes executing ( takes up more memory)
Local variables deleted after subroutine finishes
2.2.1 C)
What happens if a local and global variable have the same name
local takes precedence
2.2.1 D)
What is modular programming
A technique used to split large, complex programs into smaller, self contained modules.
2.2.1 D)
What is top down approach / stepwise refinement
problems continually broken down into sub problems until it can be represented as individual, self contained black box which preforms a certain task.
2.2.1 D)
What is the adv of modular programming
makes problem easier to understand and approach. Also makes it easier to divide takes between a team and manage. This improves testing / maintenance as its dealt with individually therefore improving reusability .
2.2.1 D)
What are procedures and functions
modules form subroutines which can be categorized as either functions or procedures
functions named blocks of code that performs a specific task. function must always return one value and typically use local variables
procedures named block of code that performs a specific task. procedures dont have to return a value but can also return multiple values
2.2.1 D)
How can parameters passed through to a subroutine
Either by value or by reference
2.2.1 D)
What happens when parameter is passed by value
They are treated like a local variable. a copy is made passed through subroutine it is discarded at the end, value outside of subroutine unaffected.
2.2.1 D)
What happens when parameter is passed by reference
Address passed through, address given to the subroutine so the value of parameter will be updated at given address
2.2.1 D)
Which parameter passing should be assumed
By value unless told otherwise
2.2.1 E)
What is an IDE and what is it used for
Integrated design environment
a program which provides a set of tools to make writing , developing and debugging code easier,
2.2.1 E)
Common feature of IDE
Stepping
Variable watch
Breakpoint
Source code editor
Debugger tool
2.2.1 E)
Common feature of IDE
What is stepping
monitor effect of each line of code by executing a single line at a time
2.2.1 E)
Common feature of IDE
What is variable watch
Sometimes used to pinpoint errors observe how content of variable change in real time
2.2.1 E)
Common feature of IDE
What is breakpoint
set a point in the program at which program will stop based on condition or specific line helps pinpoint error.
2.2.1 E)
Common feature of IDE
What is source code editor
make writing easier with auto completion of words, indentation, syntax highlight
2.2.1 E)
Common feature of IDE
What is debugging tool
run time detection of errors with a guild to where in the code likely to be. Through line number / highlights.