The statement if (f > 6 ∣∣ f == 5) g=0; will set the variable g to 0.
Which statemen will set the variable g to 0 ?
From the question, we have the following parameters that can be used in our computation:
f = 5
Considering the options:
The statement if (f > 6 ∣∣ f == 5) g=0; will set the variable g to 0.
This is so because
This statement uses the || operator, which means "or".
So, it checks if either of the following conditions are true:
- f > 6: This checks if f is greater than 6. We know f is initialized to 5, so this condition is false.
- f == 5: This checks if f is equal to 5. We know f is 5, so this condition is true.
Since at least one condition is true (f == 5), the entire statement is true and g will be set to 0.
Question
Assuming a variable f has been initialized to 5 , which of the following statemens will set the variable g to 0 ?
if (f >6 ∣∣ f == 5) g=0;
if (f > 3 &&f < 7) g = 0;
if (f > 6) g=0;