Programming concepts Flashcards

1
Q

What does a variable do?

A

Holds values that can be modified when the program is executed

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

What does a constant do?

A

Holds values that remain unchanged when a program is executed

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

How do you assign a variable?

A

Declare the name and data type, then assign a value

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

What are the three main steps to using variables?

A

Declaration, Assignment, and Initialisation

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

What is declaration?

A

Creating space in memory for a variable or constant

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

What is assignment?

A

Setting the contents of the memory space to a value

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

What is initialisation?

A

Setting the value of a variable before any processing takes place

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

Name the advantages of using constants

A

You can use the same identifier throughout a program which keeps the program code consistent- making it easy to debug and read, if errors occur changes only need to be made at one point- the initialising of the constant

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

Define an identifier

A

A name given to any variable, constant, subroutine, or class

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

Why are meaningful identifiers important?

A

So the purpose of the subroutine is clear to anyone reading your code

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

What are definite loops and how are they implemented? give an example

A

A set of instructions repeated a certain number of times, implemented by count-controlled loops e.g. for

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

What are indefinite loops and how are they implemented? give an example

A

A set of instructions that are repeated until a condition is met, implemented by condition control loops e.g. while

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

When does a while loop check its condition?

A

At the start of each iteration until the condition is met

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

When does a repeat until loop check its condition?

A

At the end of each iteration until the condition is met

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

What is nested iteration?

A

When a loop is inside another loop

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

How does nested iteration work?

A

The inner loop will be executed for all the iterations of the outer loop

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

Define sequence

A

A series of instructions that a program executes in order, one after another

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

How does selection differ from sequence?

A

Selection executes a program based on a condition

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

What is nested selection used for?

A

Implementing branching logic

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

What is branching logic?

A

If a condition of the main selection block evaluates to true then it leads to sub-conditions which are included inside the main condition

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

What are operands?

A

The values in calculations to which arithmetic operators are applied

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

`What does DIV do?

A

Returns ONLY the whole number part of a division, the fractional part is dismissed

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

What does MOD do?

A

Returns ONLY the remainder of a division

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

What does Round() do?

A

Rounds up the result of an operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does Truncate do?
Rounds down the result of an operation
26
What are relation operators used for?
Comparing the values of 2 variables or comparing a given value against a variable
27
What do expressions with relational operators evaluate to?
True or False
28
What are logical operators used for?
Combining multiple factors in a program using logical operators
29
What do expressions with logical operators evaluate to?
True or False
30
When does an AND statement evaluate to True?
When all operands equal True
31
When does an OR statement evaluate to True?
When either of the operands is True
32
When does a NOT statement evaluate to True?
When the operand is equal to False as it reverses its value
33
What is the default order of operations in logical statements(when no brackets are present)?
1. NOT 2. AND 3. OR
34
How are arrays and strings similar?
Each character in a string is indexed but it is immutable( once it's created it can't be changed)
35
Define exception
An exceptional or unexpected event that occurs when a program is running
36
What is exception handling?
The way a program deals with exceptional circumstances without crashing
37
What is a subroutine?
A section of code that can be called by writing the subroutines name in a statement
38
What are the 2 types of subroutine?
Function and procedure
39
What's the difference between a procedure and a function?
Procedures simply execute a set of instructions whereas functions return a value after running
40
Advantages of subroutines
Makes code readable and reusable, shorten programs, subroutines can be tested separately,
41
What does a parameter do?
Defines the data that must be passed into a subroutine when it's called
42
What is an argument?
A piece of data that is passed into a subroutine
43
Which type of subroutine returns a value?
Function
44
What is the scope of a variable?
Where in the program a variable or constant can be accessed
45
Define local variable
A variable that is only accessible within a specific part of a program
46
Do local variables in different subroutines need different names and why?
No, because they're kept in separate
47
Define global variable
A variable that can be accessed anywhere in the program
48
Where are global variables defined?
Outside of the subroutine
49
What's the problem with global variables?
Their values can be altered anywhere so can be changed accidentally
50
if a local variable and global variable have the same, which takes precedence?
The local variable will be taken first but will not override the global variable
51
What is a call stack?
An area of memory allocated to a program to store information about each active subroutine
52
What is an active subroutine?
A subroutine that's been called but hasn't finished executing
53
What does a stack frame store?
The value of any local variables ad the value of any parameters
54
What is a recursive algorithm?
An algorithm that calls itself
55
What's a general case?
A statement that expresses the solution to a problem in terms of a reference to a smaller version of that same problem
56
What's the base case?
The point at which you know the answer to a specific version of a problem
57
What are the criteria for a recursive algorithm, in order?
Define a base case, define the general case
58
Write the general case for any function
sum_to_n(n) = n + sum_to_n(n-1)
59
Write the base case for any function
sum_to_n(1) = 1
60
Are parameter values passed byval or byref in recursive routines?
Byval
61
Advantages of recursion
Natural way to process data structures that are recursive by nature( like trees), Fewer lines of code
62
Disadvantages of recursion
Harder to trace, uses more memory, slower to run