Programming concepts Flashcards

You may prefer our related Brainscape-certified 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
Q

What does Truncate do?

A

Rounds down the result of an operation

26
Q

What are relation operators used for?

A

Comparing the values of 2 variables or comparing a given value against a variable

27
Q

What do expressions with relational operators evaluate to?

A

True or False

28
Q

What are logical operators used for?

A

Combining multiple factors in a program using logical operators

29
Q

What do expressions with logical operators evaluate to?

A

True or False

30
Q

When does an AND statement evaluate to True?

A

When all operands equal True

31
Q

When does an OR statement evaluate to True?

A

When either of the operands is True

32
Q

When does a NOT statement evaluate to True?

A

When the operand is equal to False as it reverses its value

33
Q

What is the default order of operations in logical statements(when no brackets are present)?

A
  1. NOT 2. AND 3. OR
34
Q

How are arrays and strings similar?

A

Each character in a string is indexed but it is immutable( once it’s created it can’t be changed)

35
Q

Define exception

A

An exceptional or unexpected event that occurs when a program is running

36
Q

What is exception handling?

A

The way a program deals with exceptional circumstances without crashing

37
Q

What is a subroutine?

A

A section of code that can be called by writing the subroutines name in a statement

38
Q

What are the 2 types of subroutine?

A

Function and procedure

39
Q

What’s the difference between a procedure and a function?

A

Procedures simply execute a set of instructions whereas functions return a value after running

40
Q

Advantages of subroutines

A

Makes code readable and reusable, shorten programs, subroutines can be tested separately,

41
Q

What does a parameter do?

A

Defines the data that must be passed into a subroutine when it’s called

42
Q

What is an argument?

A

A piece of data that is passed into a subroutine

43
Q

Which type of subroutine returns a value?

A

Function

44
Q

What is the scope of a variable?

A

Where in the program a variable or constant can be accessed

45
Q

Define local variable

A

A variable that is only accessible within a specific part of a program

46
Q

Do local variables in different subroutines need different names and why?

A

No, because they’re kept in separate

47
Q

Define global variable

A

A variable that can be accessed anywhere in the program

48
Q

Where are global variables defined?

A

Outside of the subroutine

49
Q

What’s the problem with global variables?

A

Their values can be altered anywhere so can be changed accidentally

50
Q

if a local variable and global variable have the same, which takes precedence?

A

The local variable will be taken first but will not override the global variable

51
Q

What is a call stack?

A

An area of memory allocated to a program to store information about each active subroutine

52
Q

What is an active subroutine?

A

A subroutine that’s been called but hasn’t finished executing

53
Q

What does a stack frame store?

A

The value of any local variables ad the value of any parameters

54
Q

What is a recursive algorithm?

A

An algorithm that calls itself

55
Q

What’s a general case?

A

A statement that expresses the solution to a problem in terms of a reference to a smaller version of that same problem

56
Q

What’s the base case?

A

The point at which you know the answer to a specific version of a problem

57
Q

What are the criteria for a recursive algorithm, in order?

A

Define a base case, define the general case

58
Q

Write the general case for any function

A

sum_to_n(n) = n + sum_to_n(n-1)

59
Q

Write the base case for any function

A

sum_to_n(1) = 1

60
Q

Are parameter values passed byval or byref in recursive routines?

A

Byval

61
Q

Advantages of recursion

A

Natural way to process data structures that are recursive by nature( like trees), Fewer lines of code

62
Q

Disadvantages of recursion

A

Harder to trace, uses more memory, slower to run