Concepts of Programming Language 10th edition
Chapter 6
For Mr. TriDjokoWahjono
Review Question
1. What is a descriptor?
The collection of the attributes of a variable.
2. What are the advantages and disadvantages of decimal data types?
Decimal data types store a fixed number of decimal digits, with the decimal point at a fixed position in the value. 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 wasteful.
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?
4. Describe the three string length options.
A static length string is a string whose length is static and set when the string is created.
A limited dynamic length string is a string that has a varying length up to a declared and fixed maximum set by the variable's definition. Such string variables can store any number of characters between zero and the maximum.
A dynamic length string is a string that has a varying length and no maximum. This option requires the overhead of dynamic storage allocation and deallocation but provides maximum flexibility.
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 in the definition. Enumeration types proved a way of defining and grouping collections of name constants, which are called enumeration constants.
A subrange type is a contiguous subsequence of an ordinal type. For example, 12..14 is a subrange of integer type.
7. In what ways are the user-defined enumerations types of C# more reliable than those of C++?
The enumeration types in C# are better than those of C++, because enumeration type variables in C# are never coerced to integer types
14. Define row major order and column major order.
In row major order, the elements of the array that have as their 1st 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 the subscript are stored first, followed by the elements of the second value of the last subscript, and so forth.
3 4 7 row major order : 3,4,7,6,2,5,1,3,8.
6 2 5 column major order : 3,6,1,4,2,3,7,5,8.
1 3 8
18. What is an access function for an array?
An 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.
19. What are the required entries in a Java array descriptor, and when must they be stored (at compile time or run time)?
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.
21. What is the purpose of level numbers in COBOL records?
The level numbers in COBOL records are used to establish a hierarchical structure of related records.
22. Define fully qualified and elliptical references to fields in records.
A 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.
In an elliptical reference, the field is named, but any of the enclosing record names can be omitted, as long as the resulting reference is unambiguous in the referencing environment.
36. What are the two common problems with pointers?
One common problem with pointers is the dangling pointer, or dangling reference which is a pointer that contains the address of a heap-dynamic variable that has been deallocated.
The common problem is a lost heap-dynamic variable which is an allocated heap-dynamic variable that is not longer accessible to the user program, i.e. it hasn't a pointer. Such variables are called garbage because they are unusable.
38. What is a C++ reference type and what is its common use?
C++ includes a special kind of pointer type called a reference type. it is used primarily for the formal parameters in function definitions. A C++ reference type variable is a constant pointer that is always implicitly dereferenced.
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.
5. What disadvantages are there in implicit dereferencing of pointers, but only in sertain 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 pointers 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 pointer can be re-assigned any number of times while a reference can't be re-assigned after initialization.
- A pointer can point to NULL while reference can never point to NULL.
- You can't take the address of a reference like you can with pointers.
- There's no "reference arithmetics" (but you can take the address of an object pointed by a reference and do pointer arithmetics on it as in &obj +5).
19. Any type defined with typedef is type equivalent to its parent type. How does the use of typedef differ in C and C++?
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
21. In what way is dynamic type checking better than static type checking?
Dynamic type checking gives more freedom and flexibility to the programmer.