by Tentra on Tue Jul 01, 2014 10:10 pm
([msg=81921]see Re: Boolean Logic in C[/msg])
Assuming you already understand basic logical operators Or, And, and Not...
!( 1 || 1 && 0 )
We start inside the parenthesis left to right. The first expression is 1 || 1, which evaluates to 1.
We've simplified a smaller expression to its result. You can think of the larger expression now as:
!( 1 && 0 )
Continuing inside the parenthesis, the next expression is 1 && 0, which is 0.
Again, replacing the smaller expression in the larger:
!( 0 )
The parenthesis serve no purpose as they only hold a value, not an expression. They can be removed, giving:
!0
"Not zero" or "Not false", which is obviously true. The expression, !( 1 || 1 && 0 ), will always evaluate to true.
Hopefully this helps. Essentially you just work down to the deepest level of parenthesis and start evaluating working to the right and eventually up to the next level of parenthesis.