UMBC CS 201, Fall 06
UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

Booleans, Relational and Logical Operators

C does NOT have a Bool data type

but the ideas of TRUE and FALSE are necessary in any language.

In C, 0 is false, and anything other than 0 is true.

Variables that will only contain "true" or "false" are called Boolean variables and are sometimes called "flags" (ugh!)

Boolean operators

Operators on boolean values consist of:

Truth Tables for AND, OR and NOT

We define boolean operators by truth tables which give the desired output for every possible combination of inputs.

Truth table - (P and Q)

P Q P && Q
FALSE FALSE FALSE
FALSE TRUE FALSE
TRUE FALSE FALSE
TRUE TRUE TRUE

Truth table - (P or Q)

p Q P || Q
FALSE FALSE FALSE
FALSE TRUE TRUE
TRUE FALSE TRUE
TRUE TRUE TRUE

Truth table -
not P

P ! P
FALSE TRUE
TRUE FALSE


CSEE | 201 | 201 F'06 | lectures | news | help

Tuesday, 22-Aug-2006 07:13:56 EDT