doubt about "!"

in this line :

if (!max && min ) {

when ! is used the whole line that is inside of the () means "not" or only "max" ??

If in doubt, check C++ operator precedence.

Only "max". Same rule like in math you've learned in basic school (I hope).

the ! applies to only one statement. in the future you could have gotten an answer much faster than posting here by doing this:

max=false;min=false;
if (!max && min ) {
Serial.print("no");
}else{Serial.print("yes");}

Serial print is your best tool for testing code and debugging in arduino land.

gabrieldamakampos:
in this line :

if (!max && min ) {

when ! is used the whole line that is inside of the () means "not" or only "max" ??

Can you not check this for yourself? Code something up that would tell you:

  if (!false && false)
    Serial.println ("condition true")

Its easy to ask the compiler questions like this!

Budvar10:
Only "max". Same rule like in math you've learned in basic school (I hope).

How?

A: Operators Table(showing precedence and associativity)


Figure-1: Table showing C++ operators

B: Example Code

bool max = false; bool min = false;
if (!max && min)

1. Fig-1 says that ! (precedence no: 3) has the higher precedence over && (precedence no: 13).

2. Fig-1 also says that the associativity of ! is from right to left.

3. So, the variable max is attached with ! operator; hence, !max will be evaluated first and will be assessed to true.

4. Now, true && min ==> true && false ==> false. (Why is not not true? It is not in the definition.)

5. The argument/condition/expression of if() structure will stand as false.

C: Verification Sketch

void setup()
{
  Serial.begin(9600);

  bool max = false; bool min = false;
  if (!max && min)
  {
    Serial.print("condition true");
  }
  else
  {
    Serial.print("condition false");
  }
}

void loop()
{

}

D: Screenshot
smOP.png

smOP.png