Programming Flashcards
Variable
Can change throughout the program
Constant
Remains fixed throughout the program
Subroutine
A block of code given a unique, identifiable name within a program
Advantages of Subroutines
- Programs become easier to write and debug
- Creates reusable components
Arithmetic Operators : MOD
How many whole numbers are left when you fit the number on the right into the number on the left as many times as you can
(e.g, 7 MOD 2 = 1 as 2 goes into 7 three times leaving 1 left)
Arithmetic Operators : ^
Power
(e.g, 5 ^ 2 = 25)
Arithmetic Operators : DIV
How many times the number on the right fits into the number on the left
(e.g, 7 DIV 2 = 3 as 2 goes into 7 three times)
Arithmetic Operators : Equal to and Not Equal to
== - Equal to
!= - Not equal to
Recursion
When a subroutine calls itself from within its own subroutine
Characteristics of a Recursive Subroutine
1.) Contains a stopping condition
2.) For any other input value other than the stopping condition, the subroutine should call itself
3.) The stopping condition should be reachable within a finite number of times
Features of a Recursive Subroutine
- Contains a stopping condition
- A function that calls itself
Recursive Subroutine Without Characteristics
Without the characteristics, a recursive subroutine may call itself indefinitely, resulting in a stack overflow
Iterative V Recursive Approach
Iterative - More efficient in memory usage
Recursive - More useful in tree traversal algorithms
Global Variable
A variable declared in the main program which exists outside any of the subroutines but can be used anywhere in the program
Local Variable
A variable declared within a subroutine of a program which only exists and can be used within that subroutine