Monday 15 April 2013

Chapter 6 - Concept of Programming Languages Tenth Edition - Robert Sebesta

Review Question chapter 6

15. What is an aggregate constant?

A parenthesized lists of values.



16. What array operations are provided specifically for single-dimensioned arrays in Ada?

catenation specified by the ampersand (&).


17. Define row major order and column major order.

Row major order (by rows) – used in most languages
Column major order (by columns) – used in Fortran


18. What is an access function for an array?
Access function maps subscript expressions to an address in the array


20. What is the structure of an associative array?

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.


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

COBOL uses level numbers to show nested records; others use recursive definition


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

Fully qualified references must include all record names.
Elliptical references allow leaving out record names as long as the reference is unambiguous.


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

record is an aggregate of data elements in which the individual elements are identified by names and accessed through offsets from the beginning of the structure.
tuple is a data type that is similar to a record, except that the elements are not named.


24. Are the tuples of Python mutable?

Python includes an immutable tuple type


25. What is the purpose of an F# tuple pattern?

A tuple pattern is simply a sequence of names, one for each element of the tuple , with or without the delimiting parentheses.


26. In what primarily imperative language do lists serve as arrays?
Python


27. What is the action of the Scheme function CAR?

The CAR function returns the first element of its list parameter.


28. What is the action of the F# fuction tl?

it is the methods of the List class, as in List.hd[1; 3; 5; 7], which returns 1.


30. On what are Python’s list comprehensions based?

A list comprehension is an idea derived from set notaion.


Problem Set Chapter 6


1. What are the arguments for and against four signed integer sizes in Java?

bytes (1 byte), short(2 bytes), integer (4 bytes), long (8 bytes). As a result, depending on the domain of the variable required, data types are used.


2. How are negative integers stored in memory?
Negative integer is stored in memory, and in most modern computer, the one on the most left (the sign bit) usually determines the sign for that integer.


6. Compare the use of Boolean data types in C++ and Java. Give emphasis on their use in conditional statements and conditional loops

C++ and Java boleaan usage is not different excpet in C++ the type is “bool” and in java it’s “boolean”, boolean data type only contains true or false, and this is usually used in a conditional statement or loops.


7. Compare the pointer and reference type variable in C++

The relationship to C pointers is that, Reference type is less powerful but safer than the pointer type inherited from C. C++ References are different from pointer in some ways

  •     It is not possible to refer directly to a reference object after it is defined
  •     Once a reference is created, it cannot be later made to reference another object, it cannot be reseated.
  •     References cannot be NULL, every reference refers to some object although it may or may not valid.
  •     Reference cannot be Uninitialized

However, reference can still be invalid if the previously valid reference:

  •     referred to an object with automatic allocation which goes out of scope
  •     referred to an object inside a block of dynamic memory which has been freed.


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
Union is used to save space. When we want to use one of the members of the union, rather than waste space for a lot of them. While in a struct, each data is located separated in memory address, therefor consuming more memories.


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

In Dynamic typing, we don’t need to initialize variables, Dynamic typing in practice, saves programmer from writing a few extra lines of codes.

No comments:

Post a Comment