Lec 5: Selections Flashcards

1
Q

What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5?

A

No guarantee that it’s true as floating point numbers are approximated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or false: in java, the word true is a boolean literal

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

will if(even = true){statement} compile and run?

A

Yes, even though it’s using = instead of ==, it will still compile and run

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is y after the following statement is executed?

x = 0;
y = (x > 10) ? 10 : -10;

A

x = -10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the order of precedence from high to low of the operators binary:
+,*,&&,||,^

A

*,+,^,&&,||

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does right or left associativity mean?

A

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))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Are assignment operators left or right associative?

A

Right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Are ALL binary operators left-associative?

A

False: All binary operators are left associative except for assignment operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List the short circuit operators

A

&&,||

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If x is false and y is true, what will x^y return?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If x is true and y is true, what will x^y return?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly