Review Questions (MIDTERM) Flashcards

(109 cards)

1
Q

what is a descriptor?

A

the collection of the attributes of a variable

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

advantages and disadvantages of decimal data types?

A

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

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

what are the design issues for character string types?

A
  1. should strings be simply a special kind of character array or primitive type?
  2. should strings have static or dynamic length?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

describe the three string length options

A
  1. static length string: the length can be static and set when the string is created
  2. limited dynamic string: allow strings to have varying length up to a declared and fixed maximum set by a variable’s definition
  3. dynamic length string: allow string to have varying length with no maximum
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

define ordinal, enumeration, and subrange types

A

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

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

what are the advantages of user-defined enumeration types?

A

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

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

in what ways are the user-defined enumeration types of C# more reliable than those of c++

A

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.

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

define static, fixed stack-dynamic, stack-dynamic, fixed heap-dynamic, and heap-dynamic. what are the advantages of each?

A

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.

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

what happens when a nonexistent element of an array is referenced in Perl?

A

A reference to a nonexistent element in Perl yields undef, but no error is reported.

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

what languages support array slices with stepsizes?

A

python, perl, and ruby

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

what languages support negative subscripts?

A

Ruby and Lua

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

what array initialization feature is available in ada that is not available in other common imperative languages?

A

Listing arrays in order in which they are to be stored or direcly assigning them to an index position using the => operator

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

How does JavaScript support sparse arrays?

A

The value of subscripts need not to be contiguous

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

what is an aggregate constant?

A

Nonscalar constant which value never change or are not changed during execution of the program

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

What array operations are provided specifically for single-dimensioned arrays in Ada?

A

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.

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

define row major order and column major order

A

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.

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

what is an access function of an array?

A

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.

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

What are the required entries in a Java array descriptor, and when must they be stored (at compile time or run time)?

A

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.

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

What is the structure of an associative array?

A

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.

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

What is the purpose of level numbers in COBOL records?

A

It represents relation between groups and elementary items in COBOL

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

Define fully qualified and elliptical references to field in records.

A

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.

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

What is the primary difference between a record and a tuple?

A

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.

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

Are the tuples of Python mutable?

A

No

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

What is the purpose of an F# tuple pattern?

A

A tuple pattern is simply a sequence of names, one for each element of the tuple , with or without the delimiting parentheses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
In what primarily imperative language do lists serve as arrays?
python
26
What is the action of the Scheme function CAR?
The CAR function returns the first element of its list parameter.
27
What is the action of the F# fuction tl?
it is the methods of the List class, as in List.hd[1; 3; 5; 7], which returns 1.
28
On what are Python's list comprehensions based?
A list comprehension is an idea derived from set notaion.
29
Define union, free union, and discriminated union.
union: a type whose variables are allowed to store different type values at different times during execution. free union: provide union constructs in which there is no language support for type checking. Discriminated union: type checking of unions require that each union include a type indicator.
30
Are the unions of Ada always type checked?
No. the user can tell the system when the type checking can be static.
31
What are the design issues for unions?
1. Should type checking be required? 2. Should unions be embedded in records?
32
Are the unions of F# discriminated?
yes
33
What are the design issues for pointer types?
1. What are the scope of and lifetime of a pointer variable? 2. What is the lifetime of a heap-dynamic variable? 3. Are pointers restricted as to the type of value to which they can point? 4. Are pointers used for dynamic storage management, indirect addressing, or both? 5. Should the language support pointer types, reference types, or both?
34
What are the two common problems with pointers?
1. Dangling pointers (dangerous) 2. Lost heap-dynamic variable.
35
Why are the pointers of most languages restricted to pointing at a single type variable?
The main reason for this is pointer arithmetic. For example, if ptr is a pointer variable that is declared to point at some variable of some data type, then ptr + index is a legal expression. The semantics of such an expression is as follows. Instead of simply adding the value of index to ptr, the value of index is first scaled by the size of the memory cell (in memory units) to which ptr is pointing (its base type). For example, if ptr points to a memory cell for a type that is four memory units in size, then index is multiplied by 4, and the result is added to ptr. The primary purpose of this sort of address arithmetic is array manipulation.
36
What is a C++ reference type, and what is its common use?
C++ includes a special kind of pointer type called a reference type that is used primarily for formal parameters.
37
Why are reference variables in C++ better than pointers for formal parameters?
because a pointer refers to an address in memory while a reference refers to an object or a value in memory.
38
What advantages do Java and C# reference type variables have over the pointers in other languages?
the reference Java and C# provide some of the flexibility and the capabilities of pointers, without the hazards.
39
Describe the lazy and eager approaches to reclaiming garbage.
Reference counters (eager approach): reclamation is gradual. Mark-sweep (lazy approach): reclamation occurs when the list of variable space becomes empty.
40
What is a compatible type?
A compatible type is one that either is legal for the operator or is allowed under language rules to be implicitly converted by compiler-generated code to a legal type.
41
Define type error
Type error is the application of an operator to an operand of an inappropriate type.
42
Define strongly typed.
Characteristic of programming language where the typing errors are always detected
43
What is nonconverting cast?
when no conversion takes place. It is merely a means of extracting the value of a variable of one type and using it as if it were of a different type.
44
Define strongly type
A programming language is strongly typed if types errors are always detected.
45
Why is Java not strongly typed?
because there are no implicit ways type errors can go undetected.
46
what is name type equivalence?
two variables have equivalent types if they are defined either in the same declaration or in declarations that use the same type name
47
what is structure type equivalence?
two variables have equivalent types if their types have identical structures
48
what is the primary advantage of name type equivalence
easy to implement but it is more restrictive
49
what is the primary disadvantage of structure type equivalence
more difficult to implement
50
what set operation models c's struct data type
Cartesian (cross) product; union
51
define operator precedence and operator associativity
Operator precedence determines which operator would be evaluated first if they were all in the same expression. Associative can be left or right and determines which operator would be evaluated first if operators with the same precedence were next to each other.
52
what is a ternary operator
The ternary operator is a concise, inline method used to execute one of two expressions based on a condition
53
what is a prefix operator
they precede the operands
54
what oerator usually has right associativty
**
55
what is a nonassociative operator
operators that have no defined behavior when used in sequence in an expression
56
what associativity rules are used by APL?
All operators have equal precedence and all operators associate right to left
57
What is the difference between the way operators are implemented in C++ and Ruby?
The difference is in Ruby, all the arithmetic, relational, and assignment operator, as well as array indexing, shifts, and bitwise logic operators, are implemented as methods while in C, it doesn't.
58
Define functional side effect.
A condition where a function changes either one of its parameters or a global variable.
59
What is a coercion?
A method of automatically converting one type of data to another.
60
What is a conditional expression?
A compound of expression that contains a condition that is implicitly converted to type bool in C++
61
What is an overloaded operator?
Operator that has different implementation depending on its arguments.
62
Define narrowing and widening conversion.
A widening conversion converts a value to a type that can include at least approximations of all of the values of the original type. A narrowing conversion converts a value to a type that cannot store even approximations of all of the values of the original type.
63
In JavaScript, what is the difference between == and ===?
It is the same but === prevent its operands from being coerced.
64
What is a mixed-mode expression?
A mixed-mode expression is one that has operands of different types
65
What is referential transparency?
if any two expressions in the program that have the same value can be substituted for one another anywhere in the program, without affecting the action of the program.
66
What are the advantages of referential transparency?
The semantics of such programs is much easier to understand than the semantics of programs that are not referentially transparent.
67
What is short-circuit evaluation?
An expression in which the result is determined without evaluating all of the operands and/or operators.
68
Name a language that always does short-circuit evaluation of Boolean expressions. Name one that never does it. Name one in which the programmer is allowed to choose.
C, C++, and Java: use short-circuit evaluation for the usual Boolean operators (&& and ||), but also provide bitwise Boolean operators that are not short circuit (& and |) Ada: programmer can specify either (short-circuit is specified with and then and or else. Ada also has a non-short circuit operators and and or.
69
How does C support relational and Boolean expressions?
Relational : -for example, inequality, the C-based languages use != Boolean : -Highest postfix ++, -- unary +, -, prefix ++, --, ! *, /, % binary +, - <, >, <=, >= =, != && Lowest ||
70
What is the purpose of a compound assignment operator?
Compound assignment operator is a shorthand method of specifying a commonly needed form of assignment. The form of assignment that can be abbreviated with this technique has the destination variable also appearing as the first operand in the expression on the right side.
71
What is one possible disadvantage of treating the assignment operator as if it were an arithmetic operator?
It provides yet another side effect
72
What two languages include multiple assignments?
Ruby and Perl
73
What mixed-mode assignments are allowed in Ada?
Ada doesn't allow mixed mode assignments.
74
What mixed-mode assignments are allowed in Java?
Java allows mixed mode assignment only if the required coercion is widening. So, int value can be assigned to a float variable, but not vice versa.
75
What mixed-mode assignments are allowed in ML?
ML doesn't allow mixed mode assignments at all!
76
What is a cast?
Explicit type conversion.
77
what is the definition of control structure
a control statement and the collection of statements whose execution it controls
78
what did bohm and jocopini prove about flowcharts
that all algorithms that can be expressed by flowcharts can be coded in a programming language with only two control statements: 1. one for choosing between two control flow paths 2. & one for logically controlled iterations
79
What is the definition of block?
Control structure is the collection of statements whose execution it controls. It determines the order of execution of statements. This group of statement is known as "Block".
80
What are the design issues for selection structures
Two way selection statement design issues Multiple selection constructs design issues
81
what is unusual about python's design of compound statements
Python uses indentation to specify compound statements. For example, if x > y : x = y print "case 1" equally indent statements are grouped as one compound statement.
82
Under what circumstances must an F# selector have an else clause?
If the expression returns a value, it must have an else clause
83
What are the common solutions to the nesting problem for two-way selectors?
The common solution to the nesting problem is to use alternating means of forming a compound statements.
84
What is unusual about C's multiple-selection statement?
The C switch statement has virtually no restrictions on the placement of the case expressions, which are treated as if they were normal statement labels. This laxness can result in highly complex structure eithin the switch body.
85
On what previous language was C's switch statement based?
ALGOL 68
86
Explain how C#'s switch statement is safer than that of C.
C# has a static semantics rule that disallows the implicit execution of more than one segment. Every segment must end with an explicit unconditional branch statement which transfer control out of the switch statement, or a goto, which can transfer control to one of the selectable segments
87
What is a pretest loop statement? What is a posttest loop statement?
Pretest means that the test for loop completion occurs before the loop body is executed and posttest means that it occurs after the loop body is executed.
88
What is the difference between the for statement of C++ and that of Java
The loop control expression in Java is restricted to boolean, unlike that of C++, even though the syntax is similar.
89
What does the range function in Python do?
It is used to count loops in Python
90
What contemporary languages do not include a goto?
Java language is the contemporary language that doesn't include a goto, the loop bodies cannot be entered anywhere but at their beginning.
91
what advantage does java's break statement have over c's break statement
Java's break statement has the advantage of allowing you to exit multiple nested loops simultaneously using labeled statements, while C's break only exits the innermost loop.
92
what are the differences between the break statement of c++ and that of java
C++'s break is unconditional unlabeled exits, meanwhile Java's one is unconditional labeled exits.
93
what is user-defined iteration control
A user defined iteration control is a type of looping structure that is primarily used for data structures. Instead of being controlled by a counter or boolean expression, it is controlled by the number of elements in a data structure.
94
what scheme function implements a multiple selection statement
cond
95
how does a functional language implement repitition
recursion
96
how are iterators implemented in ruby
Ruby predefines several iterator methods, such as times and upto for counter-controlled loops, and each for simple iterations of arrays and hashes.
97
what language predefines iterators that can be explicitly called to iterate over its predefined data structures
Ruby: TIMES, EACH, UPTO Or: php: CURRENT, NEXT, PREV
98
What common programming language borrows part of its design from Dijkstra's guarded commands?
Dijkstra's guarded commands are the basis of concurrence mechanism in CSP and Ada, also function definitions of Haskell.
99
what are the three general characteristics of subprograms
1. Each subprogram has a single entry point. 2. The calling program unit is suspended during the execution of the called subprogram, which implies that there is only one subprogram in execution at any given time. 3. Control always returns to the caller when the subprogram execution terminates.
100
What does it mean for a subprogram to be active?
The subprogram has been called and is executing, but has not yet terminated
101
What is given in the header of a subprogram?
name, kind of subprogram, and the formal parameters
102
What characteristic of Python subprograms sets them apart from those of other languages?
function definitions are executable; in all other languages, they are non-executable
103
What languages allow for a variable number of parameters?
c#, ruby, python, and lua
104
what is a ruby array formal parameter
105
what is a parameter profile? what is a subprogram protocol?
parameter profile of a subprogram contains the number, order, and type of its formal parameters protocol of a subprogram is its parameter profile plues, if it is a function, its return type
106
what are formal parameters? what are actual parameters?
formal parameters: parameters in the subprogram header. they are bound to storage only when the subprogram is called, and that binding is often through some other program variables. actual parameters: list of parameters to be bound to the formal parameters of the subprogram
107
what are the advantages and disadvantages of keyword parameters?
The advantage of keyword parameters is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.
108
What are the differences between a function and a procedure?
Functions return values and procedures do not.
109
What are the advantages and disadvantages of dynamic local variables?
3ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp