Chapter 7

Concepts of Programming Languages 10th Edition – Robert W. Sebesta
Page 362-365
Lecturer : Tri Djoko Wahjono

Review Questions (Randomly 10 of 28)

  1. Define operator precedence and operator associativity. (Number 1)
    Operator precedence is a rule used to clarify which procedures should be performed first in a given mathematical expression. Operator associativity is a property that determines how operators of the same precedence are grouped in the absence of parentheses.
  2. What is a ternary operator? (Number 2)
    – O
    perator with three operands.
  3. What is a prefix operator ? (Number 3)
    An operator which precede their operands.
  4. What operator usually has right associativity ? (Number 4)
    The “*” (pointer) operator.
  5. What is a nonassociative operator ? (Number 5)
    An operator that have no defined behavior when used in sequence in an expression.
  6. What associativity rules are used by APL? (Number 6)
    All operators have equal precedence and all operators associate right to left.
  7. Define functional side effect (Number 8)
    A condition where a function changes either one of its parameters or a global variable.
  8. What is an overloaded operator? (Number 11)
    The multiple use of an operator is called operator overloading.
  9. What is a mixed-mode expression? (Number 14)
    There are more than one type of operand in the expression.
  10. What is short-circuit evaluation? (Number 18)
    The result of expression is determined without all of the operands and/or operators.

Problem Sets (Randomly 7 of 22)

  1. When might you want the compiler to ignore type differences in an expression ? (Number 1)
    When you want to evaluate a string as a number and vice-versa.
  2. State your own arguments for and against allowing mixed-mode arithmetic expressions. (Number 2)
    FOR : A mixed mode arithmetic expression is needed in calculating expressions that might have decimal results. It is compulsory as it allows two different type of number data type such as float and integer to be summed without losing the precision of the float. Against : While it is compulsory to have mixed-mode expressions, it is more error prone when expressions made are more likely to have non-decimal results. A mixed mode might produce a decimal result even though the result wanted is a non-decimal.
  3. Do you think the elimination of overloaded operators in your favorite language would be beneficial ? why or why not ? (Number 3)
    No, it would not be beneficial. Overloading operator would be a helpful feature in developing a complex program with complex arithmetic operation as well. It allows developers to create a class whose function can replace countless lines of codes with an operator. This clearly will help a readability and writability of a program. Eliminating overloaded operators would null this advantage.
  4. Would it be a good idea to eliminate all operator precedence rules and require parentheses to show the desired precedence in expressions? Why or why not? (Number 4)
    No , it would not be a good idea. Although this custom precedence sounds like increasing flexibility, requiring parentheses to show a custom precedence would impact in readability and writability of a program.
  5. Should C’s assigning operations (for example, +=) be included in other languages (that do not already have them)? Why or why not? (Number 5)
    Yes, because it’s simpler than the normal <operand> = <operand> + <some values> form, and it can save much time.
  6. Should C’s single-operand assignment forms (for example, ++count) be included in other languages (that do not already have them)? Why or why not? (Number 6)
    Yes, because it’s simpler than the normal addition <operand> = <operand> + 1; and it can save much time.
  7. Describe a situation in which the ad operator in a programming language would not be communicative. (Number 7)
    An expression such as : x + fun(y), and fun(y) changes x.
This entry was posted in KBP. Bookmark the permalink.

2 Responses to Chapter 7

  1. We stumbled over here different page and thought I might check things out.
    I like what I see so i am just following you. Look forward to looking into your
    web page again.

  2. Hi there! I could have sworn I’ve visited this website before but after looking at some of the posts I realized it’s new to me.
    Anyways, I’m certainly happy I discovered it and I’ll
    be bookmarking it and checking back often!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s