+ 3
if - else
x=3; y=8; if(!(x>2) || (y<0)) - this should be readed as IF x NOT greater than 2 is TRUE. Since the x=3 the condition returns FALSE.
20 odpowiedzi
+ 17
1) x>2 is true, so applying ! on it, will make it false
2) since, 1st condition is false, so there will be need to check 2nd condition to determine final result [bcz of || operator]
Note : if 1st condition will be true, then 2nd condition will not be evaulated as result will be true only(independent of 2nd condition) [this is also known as short-circuiting (for || operator)]
+ 4
No brother.
It will check whole condition and if one of these both will be true then it will return true.
You better check it on code playground by making a code.
+ 3
This whole condition will return true.
The first condition is !(x > 2) Will be false, because x is greater then 2 but the ! will make the answer reverse so it is false.
And second condition is y less than 100 which is true.
"||" This sign is or sign which means if one of both condition is true, it will return true.
+ 2
No, that is not the explanation. First condition you have 3 > 2 evaluated to Boolean "true", but before that condition is logical"not" => first condition becomes "false". The second condition is true 8<100. Then logical "OR" first condition false , second true, so the condition is true. Hope it helps you.
+ 2
Then it's false 😐
+ 2
No brother.
You are wrong in that case.
I have learnt c, c++ and Java.
It will always check all conditions and then it will return true or false.
+ 2
Run this code.
Here first condition is false and second it true.
#include <stdio.h>
int main() {
int a = 10, b = 20;
if(a > 10 || b==20)
{
printf("Test");
}
return 0;
}
+ 1
I think you write something completely different. It's the last question in "logical operators", but logical "NOT" is applied to the result of the conditions in the brackets. So the result is false.
+ 1
No, logical "NOT" is applied after evaluation of both of the conditions in the brackets.
+ 1
Diego Acero
You mean he is wrong in putting parentheses?
+ 1
As TheWhiteCat💡 mentioned, the logical “NOT” is applied after evaluating “(x > 2 || y < 0)”.
(x > 2 || y < 0) evaluates to true because the first condition is true.
Then, the logical “NOT” makes the whole expression false.
Thus, we have:
if False:
printf("true");
else:
printf("false");
Which clearly prints “false”.
0
it will return FALSE because || operator chek the first TRUE statment and that is x is > than 2. It wont check second condition.
0
It's in the C tutorial (conditions) , this task, and the correct answer is False.
0
A little correction. I was wrongly typed "100" instead of "0".
Sry
0
But the truth is that in C, || operator checks the first true condition if he founds the true in first condition it wont check second one. In this case the truth is x > 2 and condition looks for !x>2.
0
Predrag The question you’re talking about is the following (which is different from the one you posted).
x = 3;
y = 8;
if(!(x > 2 || y < 0))
printf("true");
else
printf("false");
0
This is the complete code from C tutorial.
x = 3;
y = 8;
int main(){
if(!(x>2) || (y<0))
printf("True");
else
printf("False");
}
0
It will evaluate the same way
0
Diego Acero i think that applays to my post that condition should be "read" as " if x NOT > than 2 - than is TRUE".
0
Thats correct.