Truth Tables

A truth table shows how a logical expression is evaluated. This is the truth table for a logical and:

&&

true

false

true

true

false

false

false

false

The first column represents the first term in the logical expression, the first row represents the second term. The intersection represents the result. So:

This is a truth table for a logical or:

||

true

false

true

true

true

false

true

false

This is a truth table for a logical eor (exclusive or):

^

true

false

true

false

true

false

true

false

This is a truth table for a logical not (also called logical negation):

!true

false

!false

true

When writing your logical expressions, it is a good idea to make them as simple as possible and try to use positive logic rather than negative. For instance, the logical expression (!(x > 0)) can be re-written without the not as (x <= 0).