UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | 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 usually called flags.

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'98 | lectures | news | help

Saturday, 12-Sep-1998 16:51:01 EDT