Skip to content

Commit

Permalink
merge #242
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed May 26, 2015
1 parent 54ed3d1 commit 26a188a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ch04/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ unsigned short usvalue = 65535; ++usvalue; // 0
```

##Exercise 4.8
>Explain when operands are evaluated in the logical AND,
logical OR, and equality operators.
>Explain when operands are evaluated in the logical `AND`, logical `OR`, and equality operators.
logical `AND` : `true` only if both its operands evaluated to `true`;
logical `OR` : `true` if either of its operands evaluated to `true`;
equality operators : `true` only if its operands are equal.
from the book:
> The logical `AND` and `OR` operators always evaluate their left operand before the right. Moreover, the right operand is evaluated if and only if the left operand does not determine the result. This strategy is known as **short-circuit evaluation**.
- logical `AND` : the second operand is evaluated if and only if the left side is `true`.
- logical `OR` : the second operand is evaluated if and only if the left side is `false`
- equality operators : `true` only if both operands have the same value, otherwise, it returns `false`.

##Exercise 4.9
>Explain the behavior of the condition in the following if:
Expand Down Expand Up @@ -188,6 +190,9 @@ vec[ival++] <= vec[ival] // incorrect. It is an **undefined behavior.**
vec[ival] <= vec[ival+1]
```

>Every value computation and side effect of the first (left) argument of the built-in logical AND operator && and the built-in logical OR operator || is sequenced before every value computation and side effect of the second (right) argument.
see [order of evaluation](http://en.cppreference.com/w/cpp/language/eval_order).

##Exercise 4.20
>Assuming that iter is a vector<string>::iterator,
indicate which, if any, of the following expressions are legal.
Expand Down

0 comments on commit 26a188a

Please sign in to comment.