The use of Variables, Constants, Inputs, Outputs & Assignments Flashcards

1
Q

Define variable

A

A variable is a value stored in memory that can change while the program is running

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

Define constant

A

A constant is a value that does not change while the program is running, and is assigned when the program is designed

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

Define assignment

A

Assignment - Giving a variable or constant a value

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

Define casting

A

Casting - Converting a variable from one data type to another

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

Give an example of casting

A

For example, integer to string.

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

What data types can a variable be

A

A variable can be an integer, character, string, real (float) or Boolean.

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

Define input

A

Input - A value is read from an input device
e.g. keyboard

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

Define output

A

Ouput - Data generated by the computer and displayed to the user.

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

State the advantages of constants over variables

A

Constants make a program easier to read as they are usually declared and assigned at the top of the program

Constants can easily be changed by the programmer in one place in a program .
Instead of changing every instance of a value throughout a program.
This leads to less chance of errors

The complier can optimise the code.
This makes a program run more quickly if constants are used instead of variables.

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

Why is casting needed

A

Casting is needed because:

Inputs from the keyboard are always characters. Multiple characters are called a string.
However to perform an addition, the Arithmetic Logic Unit (ALU) must use numbers.
Therefore a string has to be “cast” to a number

Integers require less bits of memory than numbers with a decimal part (real numbers)
Therefore it makes sense to use integers where we can to make a program more memory efficient.
However, it may be necessary to cast an integer to a real in a program.

Some commands also require data in a particular data type

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

What is an integer

A

An integer is a whole number
(positive or negative)

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

When would you use and not use integers

A

Use: total = total + score

Never use for telephone numbers

Use only when arithmetic on the data is required

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

Give an example when an integer would be used in a piece of code

A

Integer
Use: total = total + score

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

What is a real

A

A real is a number with a decimal part

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

What is a real also called

A

Real also called a float (floating point number

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

Example of an real

A

6.5

17
Q

Give an example when an real would be used in a piece of code

A

Real
Use: cost = total + vat

18
Q

What is a character

A

A character is a single alphanumeric

19
Q

Give an example of a character

A

Character
E.g. “1” or “a” (“1” on the keyboard pressed would be the character “1” not the number “1”)

20
Q

Give an example of code where a character would be used

A

Character -
Use: choice = input(“Enter your choice”)

21
Q

What is a string

A

A string is multiple alphanumeric characters

22
Q

What do you use string for

A

Strings are used for words and telephone numbers

23
Q

Give an example of a string
Give an example of when a string would be used in a piece of code

A

String

E.g. “Craig”

Use: forename = “Craig”