0% found this document useful (0 votes)
68 views2 pages

Ch7 Review Q

Operator precedence and associativity rules define the order that operators are evaluated in an expression. A ternary operator takes three arguments and can return values of different types. Prefix operators precede their operands. Assignment operators are usually right associative. Referential transparency makes programs easier to reason about by allowing expressions to be replaced by their values without changing the program. Compound assignment operators provide a shorthand for assignments where the destination variable is also the first operand.

Uploaded by

Khizra Asaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views2 pages

Ch7 Review Q

Operator precedence and associativity rules define the order that operators are evaluated in an expression. A ternary operator takes three arguments and can return values of different types. Prefix operators precede their operands. Assignment operators are usually right associative. Referential transparency makes programs easier to reason about by allowing expressions to be replaced by their values without changing the program. Compound assignment operators provide a shorthand for assignments where the destination variable is also the first operand.

Uploaded by

Khizra Asaf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CHAPTER 7

1. Define operator precedence and operator 10. What is conditional expression?


associativity. A conditional expression is a compound
Operator precedence rules of expression expression that contains a condition that is
evaluation define the other in which ‘adjacent’ implicity converted to type bool in C++
operators of different precedence levels are (operand1), an expression to be evaluated if the
evaluated. Operator associativity rules for condition evaluates to true (operand2), and an
expression evaluation define the order in which expression to be evaluated if the condition has
adjacent operators with the same precedence the value false (operand3).
level are evaluated. 11. What is an overloaded operator?
2. What is ternary operator? An overloaded operator if use of an operator
A ternary operator is an operator that takes for more than one purpose.
three arguments. The arguments and result can 12. Define narrowing and widening
be of different types. conversions.
3. What is prefix operator? Narrowing conversion is one that converts an
A prefix operand means has some operators, object to a type that cannot include all of the
which means they precede their operands. values of the original type, example: float to int.
4. What operator usually has right Widening conversions is one in which an object
associativity? is converted to a type that can include at least
= is usually right associative approximations to all of the values of the
5. What is a nonassociative operator? original type, example: int to float.
Nonassociative operator is operator that has no 13. In JavaScript, what is the difference
defined behavior when used in sequence in an between == and ===?
expression. === is similar to their relatives, == but prevent
their operands from being coerced.
6. What associativity rules are used by APL?
14. What is a mixed-mode expression?
Associativity rules are used by APL: all operators Mixed-mode expression is one that has
have equal precedence and all operators operands of different types.
associate right to left. 15. What is referential transparency?
7. What is the difference between the way
Referential transparency is a property whereby
operators are implemented in
C++ and Ruby? an expression can be replaced by its value
The difference is in Ruby, all the arithmetic, without affecting the program.
relational, and assignment operator, as well as 16. What are the advantages of referential
array indexing, shifts, and bitwise logic transparency?
operators, are implemented as methods while The main advantage of referential transparency
in C, it doesn't. is that it makes it much easier to reason about
8. Define functional side effect. programs, and to apply program
Functional side effect when a function changes transformations, including optimizations and
a two-way parameter or a non-local variable. partial evaluations at compile-time.
9. What is coercion? 17. How does operand evaluation order
Coercion is when Lua performs automatic interact with functional side
conversion of numbers to strings and vice versa effects?
where it is appropriate.
If neither of the operands of an operator has compound assignment operator is a shorthand
side effects, then operand evaluation order is method of specifying a commonly needed form
irrelevant. Therefore, the only interesting case of assignment. The form of assignment that can
arises when the evaluation of an operand does be abbreviated with this technique has the
have side effects. For one example: a + fun(a) If destination variable also appearing as the first
fun does not have the side effect of changing a, operand in the expression on the right side.
then the order of evaluation of the two 22. What is the associativity of C’s unary
operands, a and fun(a), has no effect on the arithmetic operators?
value of the expression. However, if fun right
changes a, there will be an effect on: a = 10; b = 23. What is one possible disadvantage of
a + fun(a); Here, fun return 10 and changes the treating the assignment operator as
value of its parameter to 20. If the value of a is if it were an arithmetic operator?
fetched first, its value is 10 and the value of the It provides yet another side effect
expression is 20. If the second operand is 24. What two languages include multiple
evaluated first, then the value of the first assignments?
operand is 20 and the value of the expression is Ruby and perl
30. 25. What mixed-mode assignments are
18. What is short-circuit evaluation? allowed in Ada?
Short-circuit evaluation means that in a Ada doesn't allow mixed mode assignments.
condition, control evaluates from left to right 26. What mixed-mode assignments are
only the necessary expressions to know wether allowed in Java?
the condition is true or false. Only widening assignment coercions are done.
19. Name a language that always does short- 27. What mixed-mode assignments are
circuit evaluation of Boolean allowed in ML?
expressions. Name one that never does it. ML doesn't allow mixed mode assignments.
Name one in which the programmer 28. What is a cast?
is allowed to choose. Explicit type convertion
C, C++, and Java: use short-circuit evaluation for
the usual Boolean operators (&& and ||), but
also provide bitwise Boolean operators that are
not short circuit (& and |)
Ada: programmer can specify either (short-
circuit is specified with and then and or else.
Ada also has a non-short circuit operators and
and or.
20. How does C support relational and Boolean
expressions?
C support relational and Boolean expression by
using the sign of >, >=, <, <= and == to express
the relational and uses the variable type of
Boolean to assign true or false or can be
represented as 1 for true and 0 for false.
21. What is the purpose of a compound
assignment operator?

You might also like