Quiz 2

3:30 pm class – November 4th, 2004

 

Name _______________  Maximum Score:  __  Earned Score:  _____

 

  1. What are the design issues for character string types? 
    1. page 239 Should strings be simply a special kind of character array or a primitive type (with no array-style subscripting operations)? 
    2. Should strings have static or dynamic length?

 

  1.  What are the two most common problems with pointers?
    1. Page 274 & 274  A dangling pointer
    2. A lost heap-dynamic variable

 

  1. How would you implement a linked list in a language that didn’t have pointers?
    1. Using arrays

 

  1. Define row major order.
    1. Page 257  "In row major order, the elements of the array that have as their first subscript the lower bound value of that subscript are stored first, followed by the elements of the second value of the first subscript and so forth.  If the array is a matrix, it is stored by rows."  a paraphrase of this that is clearer OR the example below
    2. Example:  If the values in the array were as shown below, the values would be stored in memory in the order: c,d,e,f,g,h,i,j,k

c.                   

d.                   

e.                   

f.                   

g.                   

h.                   

i.                     

j.                    

k.                   

 

  1.  What array operations are provided specifically for single-dimensioned arrays in Ada?
    1. Page 252-253  catenation  OR
    2. Page 255  slices (those consisting of consecutive elements of a single-dimensioned array)

 

Quiz 2

5:00 pm class – November 4th, 2004

 

Name _______________  Maximum Score:  __  Earned Score:  _____

 

  1. What is a descriptor ?
    1. Page 235 – A descriptor is the collection of attributes of a variable. 
    2. In an implementation, a descriptor is the collection of memory cells that store variable attributes.

 

  1. What are the design issues for arrays?
    1. Page 248 – What types are legal for subscripts?
    2. Are subscripting expressions in element references range-checked?
    3. When are subscript ranges bound?
    4. When does array allocation take place?
    5. Are ragged or rectangular multidimensional arrays allowed, or both?
    6. Can arrays be initialized when they have their storage allocated?
    7. What kinds of slices are allowed, if any?

 

  1. Define column major order.
    1. Page 257 –" In column major order, the elements of an array that have as their last subscript the lower bound value of that subscript are stored first, followed by the elements of the second value of the last subscript, and so forth.  If the array is a matrix it is stored by columns."  a paraphrase of this that is clearer OR the example below
    2. Example:  If the values in the array were as shown below, the values would be stored in memory in the order: c,f,i,d,g,j,e,h,k

c.                   

d.                   

e.                   

f.                   

g.                   

h.                   

i.                     

j.                    

k.                   

 

  1. What are the advantages of user-defined enumeration types?
    1. age 245 – readability and reliability

 

 

  1. What array initialization features is available in Ada that is not available in other common imperative languages?
    1. Page 252 – it can assign elements to an index position using the => operator, which in Ada is called an arrow.   OR
    2. Example:   bunch : array (1..5) or integer := (1 => 3, 3 => 4, others => 0);