1. What is a descriptor?
A descriptor is the collection of the attributes of a variable. In a implementation, a descriptor is an area of memory that stores the attributes of a variable. If the attributes are all static, descriptors are required only at compile time. These descriptors are built by the compiler, usually as a part of the symbol table, and are used during compilation. For dynamic attributes, however, part or all of the descriptor must be maintained during execution. In this case, the descriptor is used by the run-time system. In all cases, descriptors are used for type checking and building the code for the allocation and deallocation operations.
2. What are the advantages and disadvantages of decimal data types?
The advantages is being able to precisely store decimal values, at least those within a restricted range, which cannot be done with floating-point. The disadvantages are that that the range of value is restricted because no exponents are allowed, and their representation in memory is mildly wasteful.
3. What are the design issues for character string types?
The design issues for character string types are if string should be simply a special kind of character array or a primitive type and if string should have static or dynamic length.
4. Describe the three string length options.
Static length string: the length that can be static and set when the string is created. This is the choice for strings of Pyhthon, the immutable objects of Java’s string class, as well as similar classes in the C++ standard class library, Ruby’s built-in string class, and the .NET class library available to C# and F#.
Dynamic length strings: string length which is used to allow string to have varying length up to a declared and fixed maximum set by the variable’s definition, as exemplified by the strings in C and the C-style st5rings of C++. Such string variables can store any number of characters between zero and the maximum. Recall that strings in C, se a special character to indicate the end of the string’s characters, rather than maintaining the string length.
5. Define ordinal, enumeration, and subrange types.
Ordinal type is one in which the age of possible values can be easily associated with the set of positive integers. In Java, for example, the primitive ordinal types are integer, char, and boolean.
Enumeration and subrange are the two user-defined ordinal type that have been supported by the programming languages.
Enumeration type is one in which all of the possible values, which are named constants, are provided, or enumerated, in the definition. Enumeration types provide a way of defining and grouping collections of named constants, which are called enumeration constants.
Subrange type is a contiguous subsequence of an ordinal type.
8. What are the design issues for arrays?
The design issues for arrays are what types legal for subscripts are, of subscripting expression ins element references range checked, when subscript range bound are, when array allocation takes place, if ragged or rectangular multidimensioned arrays allowed or both, if arrays can be initialized when they have their storage allocated, what kinds of slices are allowed if any.
9. Define static, fixed stack-dynamic, stack-dynamic, fixed heap-dynamic, and beap-dynamic arrays. What are the advantages of each?
Static array is one in which the subscript ranges are statically bound and storage allocation is static (done before run time). The advantages of static arrays is efficiency. No dynamic allocation or deallocation is required. The disadvantage is that the storage for the array is fixed for the entire execution time of the program.
A fixed stack-dynamic array is one in which the subscript ranges are statically bound, but the allocation is done at declaration elaboration time during execution. The advantage of it over the static array is space efficiency. A large array in one subprogram can use the same space as a largae array in a different subprogram, as long as both subprograms are not active at the same time. The same is true if the two arrays are in different blocks that are not active at the same time. The disadvantages is the required allocation and deallocation time.
A stack-dynamic array is one in which both the subscript ranges and the storage allocation are dynamically bound at elaboration time. Once the subscript ranges are bound and the storage is allocated, however, they remain fixed during the lifetime of the variable. The advantage of stack-dynamic arrays over static and fixed stack-dynamic array is flexibility. The size of an array need not be known until the array is about to be used.
A fixed heap-dynamic array is similar to a fixed stack-dynamic array, in that subscript ranges and the storage binding are both fixed after storage is allocated. The differences are both the subscript ranges and storage bindings are done when the user program requests them during execution, and the storage is allocated from the heap, rather than the stack. The advantages of fixed heap-dynamic arrays is flexibility – the array’s size always fits the problem.
A heap-dynamic array is one in which the binding of subscript ranges and storage allocation is dynamic and can change any number of times during the array’s lifetime. The advantage of heap-dynamic arrays over the others is the flexibility: Arrays can grow and shrink during program execution as the need for space changes.
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.
22. Define fully qualified and elliptical references to fields in records.
Fully qualified reference to fields in records is one in which all intermediate record names, from the larges enclosing record to the specific field, are named in the reference.
Elliptical references to fields in records is when the field is named, but any or all of the enclosing record names can be omitted, as long as the resulting reference is unambiguous in the referencing environment.
24. Are the tuples of Python mutable?
No, they aren’t.
25. What is the purpose of an F# tuple pattern?
The purpose is to allow functions to return multiple values.
27. What is the action of the scheme function CAR?
The CAR function returns the first element of its list parameter.
35. What are the design issues for pointer types?
The design issues for pointer types are what the scope and lifetime of a pointer variable are, what the lifetime of a heap-dynamic variable (the value a pointer references) is, if pointers are restricted as to the type of value to which they can point, if pointers are used for dynamic storage management, indirect addressing, or both, and if the language should support pointer types, reference type, or both.
44. Define type error.
Type error is the application of an operator to an operand of an inappropriate type.
45. Define strongly typed.
A programming language is strongly typed if type errors are always detected. This requires that the type of all operand can be determined, either at compile time or at run time. The importance of it lies in its ability to detect all misuses of variables that result in type error. It also allows the detection, at run time, of uses of the incorrect type value in variables that can store values of more than one type.
1. What are the arguments for and against four signed integer sizes in Java?
Arguments for and against four signed integer sizes in Java are byte, short, int, and long.
2. How are negative integers stored in memory?
Negative integers are stored in memory by using a notation called twos complement to store negative integers, which is convenient for addition and subtraction. In twos-complement notation, the representation of a negative integer is formed by taking the logical complement of the positive version of the number and adding one.
3. The collection of values that can be represented by a floating-point type is defined in terms of precision and range. What are precision and range? Show the IEEE Floating-Point standard 754 format for single- and double- precision representation.
Precision is the accuracy of the fractional part of a value, as the number of bits.
Range is a combination of the range of the fraction, more important, the range of exponents.
IEEE Floating-Point standard 754 format for single-representation.
[sign bit][Exponent (8bits)] Fraction (23bits)]
IEEE Floating-Point standard 754 format for double-representation.
[sign bit][Exponent (11bits)] Fraction (52bits)]
9. C provides two derived data types both for name and structure type equivalence: struct and union. Make a study on when to use struct type variables and union type variables.
We use struct type variable when members are laid out one after each other (with optional padding in between). We use union type variable when members overlay the memory of each other so that the sizeof of a union is the one .
19. Any type define with typedef is type equivalent to its parent type. How does the use of typedef differ in C and C++?
The use of typedef differs in C and C++ that C uses name type equivalence for structure, enumerations, and unions is if two structures, enumeration, or unions are defined in different files, in which case structural type equivalence is used. This is a loophole int the name type equivalence rule to allow equivalence of structures, enumerations, and unions that are defined in different files.
21. In what way is dynamic type checking better than static type checking?
Dynamic type checking is better than static type checking in way of a language allowing a memory cell to store values of different types at different times during execution. Such memory cells can be created with Ada variant records, C and C++ unions, and the discriminated unions of ML, Haskell, and F#. In these cases, type checking, if done, must be dynamic and requires the run-time system to maintain the type of the current value of such memory cells. So, even though all variables are statically bound to types in languages such as C++, not all type errors can be detected by static type checking.