Saturday, April 6, 2013

Concepts of Programming Languages 10th Edition : Chapter 6


Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT


Review Questions
1. What is a descriptor?
=> descriptor is the collection of the attributes of a variable. In an implementation, a descriptor is an area of memory that stores the attributes of a variable.

2. What are the advantages and disadvantages of decimal data types?
=> Decimal types have the advantage of being able to precisely store decimal values, at least those within a restricted range, which cannot be done with floating-point. The disadvantages of decimal types are that the range of values is restricted because no exponents are allowed, and their representation in memory is mildly wasteful, for reasons discussed in the following paragraph.

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

 8.    What are the design issues for arrays?
=> The primary design issues specific to arrays are the following:
                    - What types are legal for subscripts?
                    - Are subscripting expressions in element references range checked?
                    - When are subscript ranges bound?
                    - When does array allocation 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?

12. What languages support negative subscripts?
=> Language that supports negative subscripts is Perl.

15. What is an aggregate constant?
=> Aggregate constant is the parenthesized lists of values in Fortran language.

17. Define row major order and column major order.
=> In Row major order is 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. 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.

32. What are the design issues for unions?
=> The design issues for unions are:
                    - Should type checking be required? Note that any such type checking must be dynamic.
                    - Should unions be embedded in records?

35. What are the design issues for pointer types?
=> The design issues for pointer types are:
                   - What are the scope and lifetime of a pointer variable?
                 - What is the lifetime of a heap-dynamic variable (the value a pointer references)?
                 - Are pointers restricted as to the type of value to which they can point?
                 -  Are pointers used for dynamic storage management, indirect addressing, or both?
                 - Should the language support pointer types, reference types, or both?

43.  What is a compatible type?
=> 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 (or the interpreter) to a legal type.

50. What is name type equivalence?
=> Name type equivalence 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?
=> Structure type equivalence means that two variables have equivalent types if their types have identical structures.

52.  What is the primary advantage of name type equivalence?
=> The primary advantage of name type equivalence is easy to implement.

53. What is the primary disadvantage to structure type equivalence?
=> The primary disadvantage to structure type equivalence is difficult to implement.


Problem Set
2.    How are negative integers stored in memory?
=> A negative integer could be stored in sign-magnitude notation, in which the sign bit is set to indicate negative and the remainder of the bit string represents the absolute value of the number.

7.    Compare the pointer and reference type variable in C++.
=> C++ pointers can point at any variable, regardless of where it is allocated. A C++ reference type variable is a constant pointer that is always implicitly dereferenced.

8.    What are the differences between the reference type variable in C++ and those of Java?
=> C++ reference type variable is a constant, it must be initialized with the address of some variable in it definition, and after initialization a reference type variable can never be set to reference any other variable, besides Java reference variables can be assigned to refer to different class instances, they are not constants.

9.    C provides two derived data types both for name and structure type equivalence: struct and union. Make a study on when to use struct type variables and union type variables.
=>  With a union, we're only supposed to use one of the elements, because they're all stored at the same spot. This makes it useful when we want to store something that could be one of several types. A struct, on the other hand, has a separate memory location for each of its elements and they all can be used at once.

21. In what way is dynamic type checking better than static type checking?
=> Dynamic type checking better than static type checking is when we want to provide more programming flexibility.

No comments:

Post a Comment