Senin, 08 April 2013

Chap 6 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta



Chapter 6 Review Question and Problem Set
Review Question
1. What is descriptor?
Answer:
Descriptor is a collection of the attributes of a variable that space in a memory what stores the attribute

2.  What are the advantage and disadvantage of decimal data type?
Answer:
Advantages:
- More precise calculation
- increase the ability to show a portion
Disadvantages:
- The range of precision in a value is limited because no exponent is allowed
- Ambiguous sign of decimal (in some standard decimal represent with coma others with period)

4. Describe the three string length option
Answer:
 - Static length string
The length of the string is set when the string is created and it is always static.
-Limited dynamic length string
This kind allows string to have varying length up to a declared and fixed maximum set by the variable’s definition.
- Dynamic length string
This option allows string to have varying length with no maximum limit such as JavaScript.

8. What are the design issues for arrays?
Answer:
The design issues for array are:
• What types are legal for subscripts?
• Are subscripting expressions in element references range checked?
• When are subscript 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?

10.  What happens when a nonexisted element of an array is referenced in Perl?
Answer:
A reference to nonexisted  element in Perl gives a result of undef but no error is reported.

13. What languages support array slices with stepsizes?
Answer:
Python, Perl and Ruby are the languages that support array slices with stepsize

17. Define row major order and column major order
Answer:
 Row major order is the way where 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.
Column major order is the way where the elements of an array that have as their last subscript the power bound value of that subscript are stored first, followed by the elements of the second value of the last subscript, and so forth.

21. What is the purpose of level numbers in COBOL record?
Answer:
The purpose of level numbers in COBOL record is to indicate their relative values of the hierarchal structure of the record.

22. Define fully qualified and elliptical reference to field in records.
Answer:
fully qualified all the intermediate names, from the largest enclosing record to the specific field, are named in the reference.
Elliptical reference is a method where enclosing record names can be omitted as long as the resulting reference is unambiguous.

24. Are the tuples of Python mutable?
Answer:
 the tuples of Python is inmmutable.

25. What is the purpose of an F# tuple pattern?
Answer:
The purpose of an F# tuple pattern is to make a multiple assignment by using the let statement

32. What are the design issues for unions?
Answer:
design issues for unions are:
-Should type checking be required? Note that any such type checking must be dynamic.
-Should unions be embedded in records?

35. What are the design issues for pointer types?
Answer:
The design issues of pointer types are
• What are the scope and lifetime of a pointer variable?
• What is the lifetime of a heap-dynamic variable (the value a pointer references)?
• Are pointers restricted as to the type of value to which they can point?
• Are pointers used for dynamic storage management, indirect addressing, or both?
• Should the language support pointer types, reference types, or both?

44. Define type error.
Answer:
Type error is an application that checks errors from operand to an operand.

45. Define strongly typed.
Answer:
Strongly typed is a method when the type error are always detected.

Problem Set

1. What are the arguments for and agonists four signed integer sizes in Java?
Answer:  Java defined int as a 32-bit number in the other hand C have either 16 or 32 bits dipending in the implementation. Four byte signed integer in java provide a large range that is enough to hold the information you need. But beside that capability, compared with int in C that only takes 2 byte fot int, the 4 byte signed integer in java takes more memory. Java defined int as a 32-bit number in the other hand C have either 16 or 32 bits dipending in the implementation.

2. How are negative integers stored in memory?
Answer: negative integer stored in memory by turning the value into binary and makes the compliment of its binary.
For example : integer 1 in binary is 0001 to get -1 the computer uses the compliment so it will be 1110. The 1110 binary might be 14 or -1 depends on the data type.

7. Compare the pointer and reference type variable in C++
Answer: pointer can be used to point the memory location of a variable and it can also assign the values to the memory location. It is quite similar with reference but in reference, only the value that is passed not the memory location. For example
int main ()
{
  int a, b;
  int *pointer;

  pointer = &a;
  *pointer = 10;
  pointer = &b;
  *pointer = 20;
printf("a is:  %d\n", a);
printf("b is: %d", b);
  return 0;
}
The output will be 
a is: 10
b is: 20
the pointer assign the value of 10 the memory location of variable pointer and it is referenced to a so the output is 10.

8. What are the differences between the reference type variable of C++ and those of Java?
Answer: The differences between the reference type variable of C++ and those of Java are first in Java we can’t actually get to and manipulate the underlying value of a reference in Java but in C we can manipulate it. Second in java references are strictly controlled than in C. Third in Java reference will be implemented as pointers, but that is not required by the specification in the other hand C reference is not implemented as pointer.

19. Any type defined with typedef is type equivalent to its parent type.
How does the use of typedef differ in C and C++?
Answer
Typedef in C uses struct to do typedef, with the fortmat typedef struct name_of struct; Typedef in c++ we don’t need to uses the keyword typedef and it has a format typedef existing_type new_type_name


21. In what way dynamic checking is better than static type checking?
Answer: Dynamic checking occurs when type information is used at runtime. In the other hand static type checking means that type checking occurs at compile time. It is better to do dynamic checking because it will be more reliable and more relevant to the information that is used during the runtime


Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.

Tidak ada komentar:

Posting Komentar