Tuesday, November 4, 2014

Chapter 6 : Review Question

Q6 : What are the advantages of user-defined enumeration types?
A   : The advantages are readability and reliability.

Q7 : In what ways are the user-defined enumeration types of C# more reliable than those of C++?
A  : C# enumeration types are like those of C++, except that they are never coerced to integer. So, operations on enumeration types are restricted to those that make sense. Also, the range of values is restricted to that of the particular enumeration type.

Q8 : What are the design issues for arrays?
A    :
-What types are legal for subscripts?
-Are subscripting expressions in element references range checked?
-When are subscript ranges bound?
-When does allocation take place?
-What is the maximum number of subscripts?
-Can array objects be initialized?
-Are any kind of slices supported?

Q9 : Define static, fixed stack-dynamic, stack-dynamic, fixed heap-dynamic, and heap-dynamic arrays. What are the advantages of each?
A     :
1. Static: subscript ranges are statically bound and storage allocation is static (before run-time)
*Advantage: efficiency (no dynamic allocation).
2. Fixed stack-dynamic: subscript ranges are statically bound, but the allocation is done at declaration time.
*Advantage: space efficiency .
3. Stack-dynamic: subscript ranges are dynamically bound and the storage allocation is dynamic (done at run-time)
*Advantage: flexibility (the size of an array need not be known until the array is to be used).
4. Fixed heap-dynamic: similar to fixed stack-dynamic: storage binding is dynamic but fixed after allocation (i.e., binding is done when requested and storage is allocated from heap, not stack).
5. Heap-dynamic: binding of subscript ranges and storage allocation is dynamic and can change any number of times.
*Advantage: flexibility (arrays can grow or shrink during program execution).

Q10 : What happens when a nonexistent element of an array is referenced in Perl?
A   : If an r-value is required, undef is returned. If an l-value is required, the array is extended, then the newly created but undefined element is returned. No error is reported.

No comments:

Post a Comment