UMBC CS 201, Fall 07
UMBC CMSC 201
Fall '07

CSEE | 201 | 201 F'07 | 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'07 | lectures | news | help

Thursday, 23-Aug-2007 12:00:52 EDT