# 5 - 5 SELECTION STATEMENTS Relational Operators The...

This preview shows pages 1–7. Sign up to view the full content.

5. SELECTION STATEMENTS

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Relational Operators The relational operators are: < less than > greater than <= less than or equal >= greater than or equal The value of a relational expression is either 1 (if the condition is true) or 0 (if it is false): 1 < 2 has the value 1 1 > 2 has the value 0 The relational operators have lower precedence than the arithmetic operators. For example: i + j < k - 1 means (i + j) < (k - 1)
Equality Operators The equality operators are: == equality != inequality The equality operators produce either 1 or 0 as their result.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Boolean Values in C89 The values true and false do not exist in C89. Instead, any numeric expression whose value is not zero is treated as a true value, and any expression whose value is zero is treated as a false value. An integer variable can be used to store a Boolean value. The variable can be assigned 1 to represent true and 0 to represent false: int flag; /* represents a Boolean condition */ flag = 1; /* condition is true */ ... flag = 0; /* condition is false */
Boolean Values in C89 To improve program readability, it is a good idea to define constants named TRUE and FALSE: #define TRUE 1 #define FALSE 0 flag = TRUE; ... flag = FALSE; Using a macro to define the name BOOL is also a good idea: #define BOOL int BOOL flag;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Boolean Values in C99 C99 has a genuine Boolean type, named _Bool . If the
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 07/08/2011 for the course CGS 3460 taught by Professor Staff during the Summer '08 term at University of Florida.

### Page1 / 20

5 - 5 SELECTION STATEMENTS Relational Operators The...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online