Monday, April 8, 2013

KBP - Chapter 6

Review Question

1. What is the descriptor?
   Descriptor is the collection of the attributes of a variable.

4. Describe the three string length options.
    - A static length string is the length that can be static and set when the string is created.
    - A limited dynamic strings is the option that allow strings to have varying length up to a declared and fixed maximum set by the variable's definition.
    - A dynamic length strings is the option that allow strings to have varying length with no maximum.

5. Define ordinal, enumeration, and subrange types.
    - An ordinaltype is one in which the range of possible values can be easily associated with the set of positive integers.
    - An enumeration is one in which all of the possible values, which are named constant, are provided, or enumbered, in the definition.
    - A subrange type is a contiguous subsequence of an ordinal type.

8. What are the design issues for arrays?
    - What types are legal for subscripts?
    - Are subscripting expressions in element references range checked?
    - When are subscript ranges bound?
    - when does array allocarion take place?
    - Are ragged or rectangular multidimensioned arrays allowed, or both?
    - Can arrays be initialized when they have their storage allocated?
    - What kinds of slices are allowed, if any?

15. What is an aggregate constant?
    An aggregate constant is a nonscalar constant which value never change or are not changed during execution of the program.

17. Define row major order and column major order.
     - 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.
     - Column major order : the elements of the 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.

31. Define union, free union, and discriminated union.
     - A union is a type whose variables may store different type values at different times during program execution.
     - A free union is the union construct is used to specify union structures.
     - A discriminated union is a union with a discriminant.

44. Define type error.
    A type error is the application of an operator to an operand of an inappropriate type.

45. Define strongly type.
    A programming language is called strongly type if type errors are always detected.

47. What is a nonconverting cast?
    A nonconverting cast is a kind of conversion that there's no actual conversion takes place, it's merely a means of extracting the value of a variable of one type and using it as if it were of a different type.

49. Why are C and C++ not strongly typed?
    Because both include union types, which are not type checked.

50. What is name type equivalence?
    It means that two variables have equivalent types if they are defined either in the same declaration or in declarations that use the same type name.

51. What is structure type equivalence?
    It means that two variables have equivalent types if their types have identical structures.

___________________________________________________
Problem Set

2. How are negative integers stored in memory?
   To store negative integers, we can use a notation called twos-complement, which is convenient for addition and subtraction.
   By using this notation, the representation of a negative integer is formed by taking the logical complement of the positive version of the number and adding one.
   Ones-complement notation is still used by some computer. With this notation, the negative of an integer is stored as the logical complemenet of its absolute value.

7. Compare the pointer and reference type variable in C++.
    - Pointer : to implement algorithms and data structures.
    - Reference : to define attractive interfaces in function parameters and return types.

8. What are the differences between the reference type variable of C++ and those of Java?
    - C++ : Pointers, references, and pass-by-value are supported.
    - Java : Primitive and reference data type parameters are always passed by value.

19. Any type defined with typedef is type equivalent to its parent type. How does the use of typedef differ in C and C++?
    Because in C, there are two different namespaces of types : a namespace of struct/union/enum tag names and a namespace of typedef names.
    While in C++, there's only a  subtle difference. It's a holdover from C, in which it made a difference.

21. In what way is dynamic type checking is better than static type checking?
     - it's simpler languages
     - lack of compile time, quicker turnaround
     - can pass variables/objects between modules without declare their type

No comments:

Post a Comment