hi
Yin and Yang Surfboard

Kamis, 06 November 2014

Chapter 6 : Data Types

From Book : Concept Of Programming  Languages 
By : Robert W. Sebesta

REVIEW QUESTION :

16. What array operations are provided specifically for single-dimensioned arrays in Ada?
Answer :
Catenation specified by the ampersand (&).


17. Define row major order and column major order.
Answer :
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.

18. What is an access function for an array?

Answer :
Access function maps subscript expressions to an address in the array


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

In Java all arrays are fixed heap-dynamic arrays. Once created, tese 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.

20. What is the structure of an associative array?

Answer :
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.

Read More

PROBLEM SET :

15. What are the arguments for and against Java’s implicit heap storage recovery, when compared with the explicit heap storage recovery required in C++? Consider real-time systems.
Answer :
Implicit eliminates the creation of dangling pointers. Disadv: cpu-time to do recovery, sometimes when there’s plenty of heap storage so recovery isn’t necessary.

16. What are the arguments for the inclusion of strong type checking in Java, although they were not included in C or C++?
Answer :

Java are strongly typed in the same sense as Ada. Types can be explicitly cast, which could result in a type error. However, there are rules of a language have an important effect on the value of an arithmetic operator with one floating-point operand and one integer operand is legal. The value of the integer operand is coerced to floating-point, and a floating point operation takes place. This is what is usually intended by the programmer.

17. What kind of conversion is called a nonconverting cast ? explain with an example in Ada language .
Answer :
Nonconverting cast is a conversion which happen between types of the same storage size.
Example :
generic
type Source (<>) is limited private;
type Target (<>) is limited private;

function Ada.Unchecked_Conversion (S : Source) return Target;

18. Make two lists of applications of matrices, one for those that require jagged matrices and one for those that require rectangular matrices. Now, argue whether just jagged, just rectangular, or both should be included in a programming language.

19. Any type defined with typedef is type equivalent to its parent type. How does the use of typedef differ in C and C++?
Answer :
C does not allow a given typedef to appear more than once in the same scope.
C++ handles typedefs and type names differently than C, and allows redundant occurrences of a given typedef within the same scope

20. Look up the definition of strongly typed as given in Gehani (1983) and compare it with the definition given in this chapter. How do they differ?
Answer :
A strongly-typed programming language is one in which each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data types. Certain operations may be allowable only with certain data types. The language compiler enforces the data typing and use compliance. An advantage of strong data typing is that it imposes a rigorous set of rules on a programmer and thus guarantees a certain consistency of results. A disadvantage is that it prevents the programmer from inventing a data type not anticipated by the developers of the programming language and it limits how "creative" one can be in using a given data type.

21. In what way is dynamic type checking is better than static type checking?
Answer :

It is better to detect errors at compile time than at the run time, because the earlier correction is usually less costly.

Tidak ada komentar:

Posting Komentar