Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does false && (false)?false:true return true

Please don't look at the condition as they are here to ease the understanding of the behavior

Why does result equals true ?

boolean result = false && (false)?false:true;

I know we can solve the issue doing:

boolean result = false && (false?false:true);

But I am just wondering why the first syntax is incorrect, looks like the '?' operator has more priority over '&&'

like image 369
Gomino Avatar asked Sep 13 '13 13:09

Gomino


People also ask

Why do false positives happen?

There are many potential causes of a false positive result, including the following: Mislabelling at the point of collection and at the point of processing. This can be guarded against by robust processes such as rigorous sampling and laboratory protocols. Contamination during sampling and processing.

What is a false negative in it?

In the case of a false negative, the test passes when a bug or security vulnerability is in fact present or the functionality is not working as it should. The more times testing tools and strategies give false negatives (as well as false positives), the less reliable and useful the results.

What is a false positive example?

Some examples of false positives: A pregnancy test is positive, when in fact you aren't pregnant. A cancer screening test comes back positive, but you don't have the disease. A prenatal test comes back positive for Down's Syndrome, when your fetus does not have the disorder(1).

Does false negative mean positive?

When you perform an at-home COVID-19 antigen test, and you get a positive result, the results are typically accurate. However, if you perform an at-home COVID-19 antigen test, you could get a false negative result. This means that the test may not detect the SARS-CoV-2 virus that is in your nasal swab sample.


1 Answers

The ternary conditional ( ?: ) has lower precedence than &&. So

boolean result = false && (false)?false:true;

(having unnecessary parentheses); is equivalent to

boolean result = (false && false) ? false : true;

Since (since false && false is false), this reduces to

boolean result = false ? false : true;

which, of course, is true.

like image 73
Bathsheba Avatar answered Oct 04 '22 01:10

Bathsheba