Chapter 6 Programming Languages

Ace your homework & exams now with Quizwiz!

3. What are the design issues for character string types?

A character string type is one in which the values consist of sequences of characters. 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 (with no array-style subscripting operations)? Should strings have static or dynamic length?

22. Explain how coercion rules can weaken the beneficial effect of strong typing?

A language that allows many type coercions can weaken the beneficial effect of strong typing by allowing many potential type errors to be masked by simply coercing the type of an operand from its incorrect type given in the statement to an acceptable type, rather than reporting it as an error.

2. What are the advantages and disadvantages of decimal data types?

Advantage of being able to precisely store decimal values, at least those within a restricted range, which cannot be done with floating-point. Disadvantage of decimal types are that the range of values is restricted because no exponents are allowed, and their representation in memory is mildly wasteful.

40. What advantages do Java and C# reference type variables have over the pointers in other languages?

Although objects pointed to by references are implicitly deallocated, that is not true for objects pointed to by pointers.

20. What is the structure of an associative array?

Associative array is an unordered collection of data elements that are indexed by an equal number of values called keys.

36. What are the two common problems with pointers?

Dangling Pointers (pointer that contains the address of a heap-dynamic variable that has been deallocated) and Lost Heap Dynamic Variables (An allocated heap-dynamic variable that is no longer accessible to the user program)

22. Define fully qualified and elliptical references to fields in records.

Fully qualified reference to a record field is one in which all intermediate record names, from the largest enclosing record to the specific field, are named in the reference. Elliptical reference, the field is name, but any or all of the enclosing record names can be omitted, as long as the resulting reference is unambiguous in the referencing environment.

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.

Implicit heap storage recovery eliminates the creation of dangling pointers through explicit deallocation operations, such as delete. The disadvantage of implicit heap storage recovery is the execution time cost of doing the recovery, often when it is not even necessary (there is no shortage of heap storage)

2. How does a decimal value waste memory space?

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.

42. Why wouldn't arithmetic on Java and C# references make sense?

Java and C# references refer to class instances and not memory addresses. This immediately presents arithmetic on these references from being sensible.

10. Multidimensional arrays can be stored in row major order, as in C++, or in column major order, as in Fortran. Develop the access functions for both of these arrangements for three-dimensional arrays.

Let the subscript ranges of the three dimensions be named min(1), min(2), min(3), max(1), max(2), and max(3). Let the sizes of the subscript ranges be size(1), size(2), and size(3). Assume the element size is 1. Row Major Order: location (a[i,j,k])=(address of a[min(1)

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. If the array is a matrix it is stored by rows. 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.

32. What are the design issues for unions?

Should type checking be required? Note that any such type checking must be dynamic. Should unions be embedded in records?

4. Describe the three string length options.

Static length string- length is static and set when the string is created. Limited dynamic length string- varying length up to a declared and fixed maximum set by the variable's definition. Dynamic length string- varying length and no maximum.

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

Static type checking is better than dynamic type checking for two reasons: first anything done at compile time leads to better overall efficiency, simply because production programs are often executed but far less often compiled. Second, type checking uncovers program errors, and the earlier errors are found the less costly it is to remove them.

18. What is an access function for an array?

The access function for a multidimensional array is the mapping of its base address and a set of index values to the address in memory of the element specified by the index values.

9. The unions in C and C++ are separate from the records of those languages, rather than combined as they are in Ada. What are the advantages and disadvantages to these two choices?

The advantage of having a separate construct for unions is that it clearly shows that unions are different from records. The disadvantages are that it requires an additional reserved word and that unions are often separately defined but included in records thereby complicating the program that uses them.

11. In the Burroughs Extended ALGOL language, matrices are stored as a single-dimensioned array of pointers to the rows of the matrix, which are treated as single-dimensioned arrays of values. What are the advantages and disadvantages of such a scheme?

The advantage of this scheme is that accesses that are done in order of the rows can be made very fast; once the pointer to a row is gotten, all of the elements of the row can be fetched very quickly. If, however, the elements of a matrix must be accessed in column order, these accesses will be much slower; every access requires the fetch of a row pointer and an address computation from there. Note that this access technique was devised to allow multidimensional array rows to be segments in a virtual storage management technique. Using this method, multidimensional arrays could be stored and manipulated theater much larger than the physical memory of the computer.

44. Define type error.

The application of an operator to an a=operand of an inappropriate type.

10. What happens when a nonexistent element of an array is referenced in Perl?

The array element is created and initialized.

23. What is the primary difference between a record and a tuple?

The elements are not named in a tuple

37. Why are the pointers of most languages restricted to pointing at a single type variable?

The main reason for this is pointer arithmetic. For example, if ptr is a pointer variable that is declared to point at some variable of some data type, then ptr + index is a legal expression. The semantics of such an expression is as follows. Instead of simply adding the value of index to ptr, the value of index is first scaled by the size of the memory cell (in memory units) to which ptr is pointing (its base type). For example, if ptr points to a memory cell for a type that is four memory units in size, then index is multiplied by 4, and the result is added to ptr. The primary purpose of this sort of address arithmetic is array manipulation.

31. Define union, free union, and discriminated union.

Union- type whose variables may store different type values at different times during program execution Free union- programmers are allowed complete freedom from type checking in their use. Discriminated union- Type checking of unions requires that each union construct include a type indicator

38. What is a C++ reference type and what is its common use?

Used primarily for the formal parameters in function definitions. C++ reference type variable is a constant pointer that is always implicitly dereferenced. Because a C++ reference type variable is a constant, it must be initialized with the address of some variable in its definition and after initialization a reference type variable can never be set to reference any other variable. The implicit dereference prevents assignment to the address value of a reference variable.

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 allocation take place? Are ragged or rectangular multi dimensioned arrays allowed, or both? Can arrays be initialized when they have their storage allocated? What kind of slices are allowed, if any?

35. What are the design issues for pointer types?

• 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 by dynamic storage management, indirect addressing, or both? • Should the language support pointer types, reference types, or both?

45. Define strongly typed

Programming language is strongly typed if type errors are always detected.

13. What languages support array slices with step sizes?

Python,Perl and Ruby.

46. Why is Java not strongly typed?

Types can be explicitly cast, which could result in a type error.

5. Define ordinal, enumeration, and subrange types

Ordinal type- the range of possible values can be easily associated with the set of positive integers. Enumeration type- all of the possible values which are named constants, are provided, or enumerated ,in the definition. Subrange type- is a contiguous subsequence of an ordinal type. Subrange types were introduced by Pascal and are included in Ada.

39. Why are reference variables in C++ better than pointers for formal parameters?

Pointer formal parameters requires explicit dereferencing, making the code less readable and less safe

7. What significant justification is there for the -> operator in C and C++?

The only justification for the -> operator in C and C++ is writability. It is slightly easier to write p -> q than (*p).q

21. What is the purpose of level numbers in COBOL records?

indicate by their relative values the hierarchical structure of the record.


Related study sets

Spanish 1B: Unit 5: Chapters 21-25

View Set

Module 6 - Troubleshooting Best Practices (Graded Quiz)

View Set

Ch 11 Public Goods and Common Resources

View Set

Life Insurance: Taxation of Life Insurance and Annuities - Premiums and Proceeds

View Set

Chapter 11: Capital Market and Investment

View Set

unit 1: the constitution and the bill of rights

View Set

Adult Health Nursing Ch. 8 and 13 Exam

View Set

Mercury, Venus, Earth,Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, Sun, Moon, Stars

View Set