Unit 7 - Variables Flashcards

1
Q

In imperative programming, a variable

A

stands for a computer memory cell (or a collection of memory cells).

Such a cell can store different values at different times and
thus it makes sense to assign a new value to a variable, overwriting the old value. It is therefore called a mutable variable.

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

A variable in functional or logical programming

A

refers to a single value during its lifetime, although unknown at the time of writing. A mathematical variable cannot change its value once it is defined. It is therefore called an immutable variable.

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

An imperative variable can be characterised by the
following six aspects:

A
  • Name, ie an identifier used in the program;
  • Scope, ie the portion of the program where one is allowed to refer to the variable
    using its name;
  • Type, ie a classifying type restricting the values (optional);
  • Lifetime(s), ie zero, one or more periods of time during execution when a piece of
    memory exists for storing a value of this variable;
  • Reference(s), ie the address of a piece of memory where a value of the variable is
    stored; this could be either one reference for each lifetime or a relative reference
    that applies to multiple lifetimes;
  • Value(s) (at each moment, there is one value for each lifetime).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A variable declaration is a piece of program text which

A
  • announces the existence of a variable with a given name,
  • (optionally) states the type of the variable and
  • (optionally) assigns an initial value to the variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The scope of a variable is the

A

portion of the program in which the programmer can refer to the variable.

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

If a scope is determined statically

A

it is usually defined by the smallest block that contains its declaration.

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

Languages in which variables have no classifying type

A

Lisp, Python,
JavaScript and PHP

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

Static type checking

A

The compiler tries to analyse all assignments to the variable and checks that the values assigned will always be compatible with the variable’s classifying type.

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

Dynamic type checking

A

The compiler inserts a code that will check every assignment at run time.

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

a classifying type is a subtype of another one if

A

its permitted values are also permitted values of the supertype.

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