Concepts of Programming Languages 10th Edition – Robert W. Sebesta
Lecturer : Tri Djoko Wahjono
Review Questions (Randomly 20 of 55)
- What is a descriptor? (Number 1)
– A descriptor is the collection of attributes of a variable.
- What are the design issues for character string types ? (Number 3)
– Should strings be simply a special kind of character array or a primitive type ? and Should strings have static or dynamic length ?
- Describe the three string length options. (Number 4)
– Static length string : the length is static and set when created. Limited dynamic length string : the length can vary up to the declared and fixed maximum set by the variable’s definition. Dynamic length string : The length varies without maximum. Stored in dynamic storage.
- Define ordinal, enumeration, and subrange types. (Number 5)
– 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.
- What are the advantages of user-defined enumeration types ? (Number 6)
– Improved writability and readibility, No arithmetic operations are legal on enum types and no enumeration types can be assigned values outside its defined range.
- In what ways are the user-defined enumeration types of C# more reliable than those of C++? (Number 7)
– The enumeration types in C# are better than those of C++, because enumeration type variables in C# are never coerced to integer types.
- What are the design issues for arrays ? (Number 8)
– What types are legal for subscripts ? Are subscripting expressions in element references range checked ? When are subscripts ranges bound ? When does array allocation take place ? Are ragged or rectangular multidimensional arrays allowed, or both ? Can arrays be initialized when they have their storage allocated ? What kinds of slices are allowed, if any ?
- Define static, fixed stack-dinamic, stack-dynamic, fixed heap-dynamic, and heap-dynamic arrays. What are the advantages of each? (Number 9)
– 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. Advantage: space efficiency, storage is allocated from heap, and binding is done when requested. 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).
- What happens when an nonexistent element of an array is referenced in Perl ? (Number 10)
– If you try to append non-existent elements from an array to another one, the initial array will grow as needed, even though the elements to append do not exist.
– The value of subscripts need not to be contiguous.
- What languages support negative subscripts ? (Number 12)
– Ruby and Lua support negative subscripts.
- What languages support array slices with stepsizes ? (Number 13)
– Python,Perl and Ruby languages.
- What array initialization feature is available in Ada that is not available in other common imperative languages ? (Number 14)
– Listing arrays in order in which they are to be stored or direcly assigning them to an index position using the => operator.
- What is an aggregate constant ? (Number 15)
– Nonscalar constant which value never change or are not changed during execution of the program.
- What array operations are provided specifically for single-dimensioned arrays in Ada ? (Number 16)
– Ada allows array assignments, including those where the right side is an aggregate value rather than an array name. Ada also provides catenation, which is defined between two single-dimensioned arrays and between a single-dimensioned array and a scalar. Nearly all types in Ada have built-in relational operators for equality and inequality.
- Define row major order and column major order. (Number 17)
– 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.
- What is an access function for an array ? (Number 18)
– 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.
- What is the structure of an associative array? (Number 20)
– 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.
- What is the purpose of level numbers in COBOL records ? (Number 21)
– The level numbers in COBOL records are used to establish a hierarchical structure of related records.
- Are the tuples of Python mutable ? (Number 24)
– Python includes an immutable tuple type. So, No.
Problem Sets (Randomly 10 of 22)
- What are the arguments for and against four signed integer sizes in Java? (Number 1)
– Bytes (1 byte), short (2 bytes), integer (4 bytes), long (8 bytes). As a result, depending on the domain of the variable required and data types are used.
- How are negative integers stored in memory? (Number 2)
– In the number, the leftmost bit is considered as a “sign bit”, which signifies whether the integers are negative or not. If it’s negative, then that bit must store 1, and 0 otherwise.
- 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. (Number 5)
– 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.
- Compare the use of Boolean data types C++ and Java. Give emphasis on their use in conditional statements and conditional loops. (Number 6)
– Basically, both data types indicates the value true / false. In C++, the name is bool while in Java it’s Boolean. Boolean values and expressions are used to determine a condition statement or loop. The main difference is that Boolean in Java can only have values true/false, while in C++, other than true/false, integer values can be used to represent true/false statement – the value 0 is false and other values are considered as true.
- Compare the pointer and reference type variable in C++. (Number 7)
– 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).
- C provides to derived data types both for name and structure type equivalence: struct and union. Make a study on when to use struct type variable and union type variables! (Number 9)
– If all data members of the variables are to be used at once, then struct type variables are required, otherwise union type variables should be used.
- In the Burroughs Extended ALGOL language, matrices are stored as a single-dimensional array of pointers to the rows of the matrix, which are treated as single-dimensional arrays of values. What are the advantages and disadvantages of such a scheme? (Number 11)
– The advantages 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. The disadvantages, 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.
- What are the arguments for the inclusion of strong type checking in Java, although they were not included in C or C++? (Number 16)
– 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.
- Any type defined with typedef is type equivalent to its parent type. How does the use of typedef differ in C and C++? (Number 19)
– 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.
- In what way is dynamic type checking better than static type checking? (Number 21)
– Dynamic type checking is done at compile time instead of run time, so dynamic type checking allows programmers to be more flexible. Moreover, static type checking do corrections later, which runs during runtime, and this is more costly compared to the dynamic type checking.