What is the difference between the conditional AND and OR operators and their logical counterparts? How can incorrect use of the logical operators lead to unintended consequences in your program?
What will be an ideal response?
The Boolean logical AND operator (&) and Boolean logical inclusive OR operator (|) work just like their && and || conditional counterparts, except they do not support short-circuit evaluation. That is, they always evaluate both sides of the expression, no matter what the first evaluation is. This can lead to a side effect, or unintended consequence. For example, in the following statement, the first half of the expression is false, so the second half of the Boolean expression is never evaluated and yearsOfService is not increased.
if (salesAmountForYear >= 10000 && ++yearsOfService > 10)
bonus = 200;
On the other hand, when a single & is used and salesAmountForYear is not at least 10,000, then even though the first half of the expression is false, the second half is still evaluated and yearsOfService is increased.
You might also like to view...
Examples of End Users in SNA include
a. a Workstation user b. an Application Program c. both a Workstation user and an Application Program d. none of the above
Terminal emulation, especially the unprotected ____________________ protocol, should be blocked from any access to all internal servers from the public network.
Fill in the blank(s) with the appropriate word(s).