Pytanie |
Odpowiedź |
rozpocznij naukę
|
|
A variable is a place holder for values at program run-time.
|
|
|
What are the attributes a variable has at run-time rozpocznij naukę
|
|
name, address, value, type, life time, scope
|
|
|
rozpocznij naukę
|
|
the name of the variable eg i or thisIsAName
|
|
|
rozpocznij naukę
|
|
an address, which is also called its l-value because the address is what is required when the name of variable appears in the left side of an assignment.
|
|
|
rozpocznij naukę
|
|
a value: the contents of the memory cell (s), also called its r-value of a variable.
|
|
|
rozpocznij naukę
|
|
a type, which determines the range of values the variable can store and the operations that are defined for the values
|
|
|
Explain variable life time rozpocznij naukę
|
|
a life time: the time during which a variable is bound to a specific memory location (i.e., its address).
|
|
|
rozpocznij naukę
|
|
a scope: the range of statements in which the variable is visible/accessible.
|
|
|
describe an explicit declaration rozpocznij naukę
|
|
An explicit declaration is a program statement used for declaring the types of variables. E.g., a variable i is declared: in Pascal: i: integer in Java int i; In Fortran: INTEGER: Count
|
|
|
Describe an implicit declaration rozpocznij naukę
|
|
default mechanism for specifying types of variables through default conventions, rather than declaration statements. eg in fortran The default implicit typing rule is if the first letter of the name is I, J, K, L, M, N the data type is integer, else real
|
|
|
rozpocznij naukę
|
|
in JavaScript and C# a variable can be declared with var and an initial value. The initial value sets the type
|
|
|
rozpocznij naukę
|
|
A binding is an association between an entity and an attribute, e.g., between a variable and its type, value or memory location, or between a symbol (e.g., +) and an operation.
|
|
|
rozpocznij naukę
|
|
the time at which a binding takes place. Binding can take place at different times
|
|
|
rozpocznij naukę
|
|
A type binding is static if it occurs before runtime and remains unchanged throughout program execution.
|
|
|
rozpocznij naukę
|
|
A type binding is dynamic if it occurs during execution or can change during execution of the program (specified through an assignment statement).
|
|
|
what are the advantages of dynamic binding rozpocznij naukę
|
|
Advantage: flexibility (generic program units)
|
|
|
What are the dissadvantages of dynamic binding rozpocznij naukę
|
|
[1] High cost (dynamic type checking and interpretation) [2] Type error detection by the compiler is difficult
|
|
|
describe a strongly typed rozpocznij naukę
|
|
If all type bindings are static, then nearly all type error (e.g., the application of an operator to an operand of an inappropriate type) can be detected by the compiler – we say the programming language is strongly typed
|
|
|
rozpocznij naukę
|
|
If type bindings are dynamic, type checking by compiler is almost impossible, then we say the programming language is weakly typed
|
|
|
rozpocznij naukę
|
|
A block is a section of code, denoted with start and end markers, which can contain declaration of variables local to that region and has its own reference environment (i.e., the accessible identifiers) eg in Java by {and }.
|
|
|
what is the cope of a variable rozpocznij naukę
|
|
The scope of an identifier (e.g. a variable or a procedure) is the part of the program text that can access that identifier.
|
|
|
What is the visibility rule rozpocznij naukę
|
|
A declaration in an inner block hides a declaration of a variable in an enclosing block with the same name
|
|
|
rozpocznij naukę
|
|
AKA Lexical scoping sets the scope (range of functionality) of a variable so that it may only be called (referenced) from within the block of code in which it is defined. The scope is determined when the code is compiled
|
|
|
rozpocznij naukę
|
|
Dynamic scoping creates variables that can be called from outside the block of code in which they are defined. and cannot be determined at compile time
|
|
|
What is the Lifetime of Variables rozpocznij naukę
|
|
The lifetime of a variable is the period when it “exists” and has a value during program execution.
|
|
|
What are the 3 basic memory allocation systems? rozpocznij naukę
|
|
Static, Stack-based, Heap-based
|
|
|
What is static memory allocation rozpocznij naukę
|
|
static allocation is when a fixed memory address is retained throughout program execution(The lifetime of the variable is the entire program execution.
|
|
|
what is stack based memory allocation rozpocznij naukę
|
|
stack-based allocation/deallocation is done on a last-in first-out basis and is used for procedure/function calls (the lifetime is the execution of the function).
|
|
|
What us heap-based memory allocation rozpocznij naukę
|
|
Heap is a memory area where storage is dynam'ly al'ctd. Var' that are dynam'ly al'ctd from the heap are called heap-dynamic var' They often do not have identifiers associated with them (anon' var') and can be ref'd only by pointers or reference type var'
|
|
|