1. Fundamentals of Programming Flashcards
What is a Data Type?
A Data Type describes how binary data of a Variable is used to represent a value. Examples of Data Types are: Integer (whole number), Float (real number), String (text), Boolean (true or false).
What is a Constant?
A Constant identifies a fixed value in memory.
What is a Variable?
A Variable identifies a value in memory which may change during the execution of the program.
What is Assignment?
Assignment is when a value is given to a Variable.
What do Sequence, Selection and Iteration refer to?
Sequence - code is executed line by line from the top of the program to the end.
Selection - a choice is made between different possibilities, for example with an IF-statement.
Iteration - code is repeated using a loop structure, for example a FOR or WHILE loop.
What is an Exception, and when do we use Exception Handling?
An Exception is an exceptional condition that arises during a program. An example would be an error caused by attempting to open a file which does not exist. Exception Handling is writing code to gracefully deal with the Exception which has occurred.
What is a Subroutine?
A Subroutine is a named block of code which can be called to perform a task.
What is a Function?
A Function is a Subroutine which returns a value when called.
What is a Parameter?
Parameters are Local Variables which hold the input values to a Subroutine. The values input into a Parameter are called Arguments.
What is the difference between Local and Global Variables?
Local Variables have a lifetime which is constrained by the scope of their enclosing subroutine. Global Variables exist throughout the entire program.
What is Concatenation?
Concatenation is when two Strings are combined together to create a new longer String.
What is a Module?
A Module is a grouping of related code into an independent unit, such as a file or library. It is often good practice to break complex programs into a series of Modules. These may also aid code re-use.
Explain the use of a Call Stack in executing Subroutines.
The Call Stack is used for memory allocation when a Subroutine is called. A Subroutine requires the following data: Parameters, Local Variables, and the return address. This data is allocated as a Stack Frame on the Call Stack. Every time a Subroutine is called it is allocating memory, and Subroutines calling other Subroutines build up the size of the Call Stack. If the Call Stack gets too big there will be a Stack Overflow which will crash the program, this is particularly an issue with Recursive Subroutines.
What is Recursion, and what is its purpose?
Recursion is when a Subroutine calls itself. Recursion allows the repetition of code without using Iteration (Loops). Recursion can lead to more elegant Algorithms than Iteration, but if the Recursion goes too deep it will cause a Stack Overflow of the Call Stack.
What is Procedural Programming?
Programs consists of Subroutines which call each other to solve a problem.