[Solved] What do these operators do in C [closed]


The key to answering this question is realization of how C treats integers that participate in logical operations:

  • Zero is treated as FALSE
  • All values other than zero are treated as TRUE

Here are the truth tables for the three operators from your code snippet:

!FALSE -> TRUE
!TRUE  -> FALSE

FALSE || FALSE -> FALSE
FALSE || TRUE  -> TRUE
TRUE  || FALSE -> TRUE
TRUE  || TRUE  -> TRUE

FALSE && FALSE -> FALSE
FALSE && TRUE  -> FALSE
TRUE  && FALSE -> FALSE
TRUE  && TRUE  -> TRUE

When multiple operators are used in an expression without parentheses, unary ! is applied ahead of the binary && or ||.

Now you have enough information to figure out the output yourself.

3

solved What do these operators do in C [closed]