Saturday, April 6, 2013

Concepts of Programming Languages 10th Edition : Chapter 5


Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

Review questions
1. What are the design issues for names?
=> The design issues for names are :
               - Are names case sensitive?
               - Are the special words of the language reserved words or keywords?

4. What is an alias?
=> Alias is the variables of names that can be used to access the same memory location.

7.    Define binding and binding time.
=> binding is an association between an attribute and an entity, such as between variable and its type or value, or between an operation and a symbol. The time at which a binding takes place is called binding time.

 9.  Define static binding and dynamic binding.
=> A binding is static if it first occurs before run time begins and remains unchanged throughout program execution. If the binding first occurs during run time or can change in the course of program execution, it is called dynamic.

11. What are the advantages and disadvantages of dynamic type binding?
=> The advantages are:
       - Dynamic type binding allows any variable to be assigned a value of any type.
       - It provides more programming flexibility.
        The disadvantages are:
       -  It causes programs to be less reliable, because the error-detection capability of the compiler is diminished relative to a compiler for a language with static type bindings.
        - The cost of implementing dynamic attribute binding is considerable, particularly in execution time.

18. What is a block?
=> A block is a section of codes.


Problem Set
  1. Decide which of the following identifier names is valid in C language. Support your decision.
_Student
int
Student
123Student
Student123
=> The valid identifiers are: _Student, Student, and Student123. It’s because an identifier in C language has its own rule. There are:
             - An identifier can’t be started with number. The number is valid as long as it is not in the front of an identifier.
               - An identifier can’t include any data types.
               - An identifier can’t be started with symbol.
               - There are not allowed if the name of identifiers if same.

 4.  Why is the type declaration of a variable necessary? What is the value range of the int type variable in Java?
=> The type declaration of a variable is necessary because, in a program it documented information about its data, which provides clues about the program’s behavior. The value range of the int type variable in Java is 32 bits (4 bytes).

10. Consider the following C program:
void fun(void) {
int a, b, c; /* definition 1 */
. . .
while (. . .) {
int b, c, d; /*definition 2 */
. . . <-1 p="">
while (. . .) {
int c, d, e; /* definition 3 */
. . . <-2 p="">
}
. . . <-3 p="">
}
. . . <-4 p="">
}
For each of the four marked points in this function, list each visible variable, along with the number of the definition statement that defines it.
=>  - In 1 and 3 : the visible variables are a, b(both), c(both), and d from definition 1 and 2.
      - In 2: the visible variables are a, b(both), c(both), d(both), and e from definition 1, 2, and 3.
      - In 4: the visible variables are a, b, and c from the definition 1.

No comments:

Post a Comment