What is the value of the bool valued expression, 1 < x < 10? Does the value of this depend on the value of x? Explain, and give the expression that the programmer probably meant.
a. This statement is incorrect as it is always false.
b. This statement is correct and its value depends on x.
c. This statement is incorrect and it is always true
d. This statement is incorrect, but it does depend on the value of x.
c) This expression is always true. The value does not depend on x. This is the mathematicians’ shorthand for what the programmer probably meant:
(1 < x)&&(x < 10)
Explanation: The < operator associates (groups) left to right, so the expression evaluates as (1 < x) < 10 . The expression (1 < x) evaluates to either false or true, regardless of x. These bool values convert to int values 0 or 1 when compared to int value 10 . The expression evaluates to true for all values of x.
You might also like to view...
A Windows Server 2008 running the web edition can act as a domain controller
Indicate whether the statement is true or false
Organizing code into two classes called the ____ and the view splits the code between managing the interface and manipulating the database.
A. model B. GUI C. application D. widget