Monday, April 8, 2013

Answers of Concepts of Programming Languages 10th - Chapter 5


Martin - 1601213690

02 PBT


Review Questions

1. What are the design issues for names?
    * Case sensitive and special words of language reserved words or keywords

4. What is an alias?
    * Alias is more than one variable name can be used to access the same memory location.

5. Which category of C++ reference variables is always aliases?
    * Looping variables.

6. What is the l-value of a variable? What is the r-value?
    * l-value is short of "left hand side value"
    * r-value is short of "right hand side value"

7. Define binding and binding time.
    * A binding in a program is an association of an attribute with a program component such as an identifier or a symbol. For example the data type of the value of a variable is an attribute that is associated with the variable name.
    * The binding time for an attribute is the time at which the binding occurs. For example, in C the binding time for a variable type is when the program is compiled, but the value of the variable is not bound until the program executes.

9. Define static binding and dynamic binding.
    * Static binding, the compiler can resolve the binding at the compile time. All the instance method calls are always resolved at runtime, but all the static method calls are resolved at compile time itself and hence we have static binding for static method calls.
    * Dynamic binding refers to the case where compiler is not able to resolve the call and the binding is done at runtime only.

10. What are the advantages and disadvantages of implicit declarations?
    * Advantage : flexibility ( generic code )
    * Disadvantage : Inefficient, because all attributes are dynamic. Loss of error detection.

11. What are the advantages and disadvantages of dynamic type binding?
    * Advantages : flexibility ( generic program units )
    * Disadvantages : high cost ( dynamic type checking and interpretation ), type error detection by the compiler is difficult.



Problem Set

1. Which of the following identifier forms is most readable? Support your decision.
    * sum_of_sales, because it's easier to see the spaces between words and easier to read.

2. Some programming languages are typeless. What are the obvious advantages and disadvantages of having no types in a language.
    * Advantages : allow users to write sloppy programs faster.
    * Disadvantages : cannot control the data and variables, compiler cannot detect any mistakes.

4. Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship.
    * Both are related to the assignment and the statement.

5. Describe a situation when a history-sensitive variable in a subprogram is useful.
    * History sensitive variables may be useful in data manipulation subprograms, where some operation is performed on a variable, and the function exits, then the function is called again. This way, the function doesn't have to take the variable as a parameter, but only to return it.

No comments:

Post a Comment