Lec 5: Selections Flashcards
What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?
No guarantee that it’s true as floating point numbers are approximated
True or false: in java, the word true is a boolean literal
true
will if(even = true){statement} compile and run?
Yes, even though it’s using = instead of ==, it will still compile and run
What is y after the following statement is executed?
x = 0;
y = (x > 10) ? 10 : -10;
x = -10
What is the order of precedence from high to low of the operators binary:
+,*,&&,||,^
*,+,^,&&,||
What does right or left associativity mean?
When 2 operators with the same precedence are evaluated, the associativity of the operators determines the order of evaluation
All binary operators except assignment operators are left-associative
a-b+c-d is equivalent to ((a-b)+c) - d
Assignment operators are right-associative
a=b+=c=5 is equivalent to a=(b+=(c=5))
Are assignment operators left or right associative?
Right
Are ALL binary operators left-associative?
False: All binary operators are left associative except for assignment operators
List the short circuit operators
&&,||
If x is false and y is true, what will x^y return?
True
If x is true and y is true, what will x^y return?
False