Review Questions (MIDTERM) Flashcards
(109 cards)
what is a descriptor?
the collection of the attributes of a variable
advantages and disadvantages of decimal data types?
advantage:
- accuracy. decimal types are able to precisely store decimal values, at leat those within a restricted range, which cannot be done by floating-point
disadvantage:
- the range of values id restricted because no exponents are allowed
- their representation in memory is mildly wasteful
what are the design issues for character string types?
- should strings be simply a special kind of character array or primitive type?
- should strings have static or dynamic length?
describe the three string length options
- static length string: the length can be static and set when the string is created
- limited dynamic string: allow strings to have varying length up to a declared and fixed maximum set by a variable’s definition
- dynamic length string: allow string to have varying length with no maximum
define ordinal, enumeration, and subrange types
ordinal type: range of possible values can be easily associated with the set of positive integers.
enumeration type: all of the possible values, which are named constants, are enumerated in the definition
subrange type: a contiguous subsequence of an ordinal type
what are the advantages of user-defined enumeration types?
aid to readability: named values are easily recognized, whereas coded values are not
aid to reliability:
1. no arithmetic operations are legal
2. no enumeration variable can be assigned a value outside its defined range
in what ways are the user-defined enumeration types of C# more reliable than those of c++
C# enumeration types are like those of C++, except that they are never coerced to integer.
So, operations on enumeration types are restricted to those that make sense.
Also, the range of values is restricted to that of the particular enumeration type.
define static, fixed stack-dynamic, stack-dynamic, fixed heap-dynamic, and heap-dynamic. what are the advantages of each?
static array: the subscript ranges are statically bound and storage allocation is static (done before run-time)
advantage: efficiency. no dynamic allocation/deallocation is required.
fixed stack-dynamic array: the subscript ranges are statically bound, but the allocation is done at declaration elaboration time during execution.
advantage: space effieciency.
stack-dynamic array: both the subscript ranges and the storage allocation are dynamically bounmd at elaboration time.
advantage: flexibility: the size of an array doesn’t need to be known until array is about to be used
fixed heap-dynamic array: similar to fixed stack-dynamic array. the diference are that both the subscript ranges and storage bindings are done when the user program requests them during execution, and the storage is allocated from the heap, rather than the stack
advantage: flexibility. the array’s size always fits the problem
heap-dynamic array: the binding of subscript ranges and storage allocation is dynamic and can change any number of times during the array’s lifetime
advantage: flexibility. arrays can grow and shrink during program execution as the need for space changes.
what happens when a nonexistent element of an array is referenced in Perl?
A reference to a nonexistent element in Perl yields undef, but no error is reported.
what languages support array slices with stepsizes?
python, perl, and ruby
what languages support negative subscripts?
Ruby and Lua
what array initialization feature is available in ada that is not available in other common imperative languages?
Listing arrays in order in which they are to be stored or direcly assigning them to an index position using the => operator
How does JavaScript support sparse arrays?
The value of subscripts need not to be contiguous
what is an aggregate constant?
Nonscalar constant which value never change or are not changed during execution of the program
What array operations are provided specifically for single-dimensioned arrays in Ada?
Ada allows array assignments, including those where the right side is an aggregate value rather than an array name.
Ada also provides catenation, which is defined between two single-dimensioned arrays and between a single-dimensioned array and a scalar.
Nearly all types in Ada have built-in relational operators for equality and inequality.
define row major order and column major order
Row major order is where elements of the array that have as their first subscript the lower bound value of the subscript are stored first.
Column major order has elements of an array that have as their last subscript the lower bound value of that subscript are stored first.
what is an access function of an array?
For multidimensional array : the mapping of its base address and a set of index values to the address in memory of the element specified by index values.
For two-dimensional array : the address of an element is the base address of the structure plus the element size times the number of elements that precede it in the structure.
What are the required entries in a Java array descriptor, and when must they be stored (at compile time or run time)?
In Java all arrays are fixed heap-dynamic arrays. Once created, these arrays keep the same subscript ranges and storage. Secondarily, Java supports jagged arrays and not rectangular arrays. Being a fixed heap-dynamic array the entries will be established and fixed at run time.
What is the structure of an associative array?
An associative array is an unordered collection of data elements that are indexed by an equal number of values called keys. User-defined keys must be stored.
What is the purpose of level numbers in COBOL records?
It represents relation between groups and elementary items in COBOL
Define fully qualified and elliptical references to field in records.
A fully qualified reference is one in which all intermediate record names, from the largest enclosing record to the specific field are named in reference.
Elliptical reference has the field named, but any or all of the enclosing record names can be omitted, as long as the resulting reference is unambiguous in the referencing environment.
What is the primary difference between a record and a tuple?
record is an aggregate of data elements in which the individual elements are identified by names and accessed through offsets from the beginning of the structure.
tuple is a data type that is similar to a record, except that the elements are not named.
Are the tuples of Python mutable?
No
What is the purpose of an F# tuple pattern?
A tuple pattern is simply a sequence of names, one for each element of the tuple , with or without the delimiting parentheses.