Senin, 08 April 2013

Concepts of Programming Languages Assignment - Chapter 6

Review Questions

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

2. What are the advantages and disadvantages of decimal data types?
The advantages of decimal data types is being able to precisely store decimal values, at least those within a restricted range, which can’t be done with floating-point. And the disadvantages of decimal data types are that the range of values is restricted because no exponents are allowed, and their representation in memory is mildly wasteful

3. What are the design issues for character sting types?
The two most important design issues that are specific to character string types are the following:
- Should strings be simply a special kind of character array or a primitive type?
- Should strings have static or dynamic length?

11.How does JavaScript support sparse arrays?
JavaScript sparse arrays means that the subscript values need not be contiguous

12. What languages support negative superscripts?
c++

13. What languages support array slices with stepsized?
Phyton, Perl, and Ruby

14. What array initialization feature is available in Ada that is not available in other common imperative languages?
Ada provides two mechanisms for initializing arrays in the declaration statement: by listing them in the order in which they are to be stored, or by directly assigning them to an index position using the => operator, which in Ada is called an arrow

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 an array that have as their last sub-script 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

20.What is the structure of an associative array?
hashes

23. What is the primary difference between a record and a tuple?
In tuple, the elements are not named

32. What are the design issues for unions?
The primary design issues that are particular to union types are the following:
- 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 primary design issues particular to pointers are the following:
- What are the scope and lifetime of a pointer variable?
- What is the lifetime of a heap-dynamic variable?
- 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?
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.

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

45. Define strongly typed.
widely acknowledged as being a highly valuable language characteristic

Problem Set

1. What are the arguments for and against four signed integer sized in Java?
Bytes =1 byte, short = 2 bytes, integer = 4 bytes, long  = 8 bytes. As a result, depending on the domain of the variable required, data types are used.

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. Sign-magnitude notation does not lend itself to computer arithmetic. Most computers now use a notation called twos complement to store negative integers, which is convenient for addition and subtraction.

5. What disadvantages are there in implicit dereferencing of pointers, but only in certain contexts? For example, consider the implicit dereference of a pointer to a record in Ada when it is used to reference a record field.
When implicit dereferencing of pointers occurs only in certain contexts, it makes the language slightly less orthogonal. The context of the reference to the pointer determines its meaning. This detracts from the readability of the language and makes it slightly more difficult to learn

7. Compare the pointer and reference type variable in C++.
A C++ reference type variable is a constant pointer that’s always implicitly dereferenced

15. What are the arguments for and against Head management’s single-size cells and variable-size cells?
Integer values stored in decimal waste storage in binary memory computers, simply as a result of the fact that it takes four binary bits to store a single decimal digit, but those four bits are capable of storing 16 different values. Therefore, the ability to store six out of every 16 possible values is wasted. Numeric values can be stored efficiently on binary memory computers only in number bases that are multiples of 2. If humans had
developed hands with a number of fingers that was a power of 2, these kinds of problems would not occur

21. In what way is dynamic type checking better than static type checking?
Static checking reduces programmer flexibility

22. Explain how the dangling-pointer problem can be removed using the locks-and-keys approach.
In the locks-and-keys approach, pointer values are represented as ordered pairs (key, address), where the key is an integer value. Heap-dynamic variables are represented as the storage for the variable plus a header cell that stores an integer lock value. When a heap-dynamic variable is allocated, a lock value is created and placed both in the lock cell of the heap-dynamic variable and in the key cell of the pointer that is specified in the call to new

Tidak ada komentar:

Posting Komentar