06-ConditionalStatements.pptx - ICS 212 Program Structure William McDaniel Albritton M.S Memory Allocation Relational Operators Logical Operators If

# 06-ConditionalStatements.pptx - ICS 212 Program Structure...

This preview shows page 1 - 15 out of 42 pages.

ICS 212 Program Structure William McDaniel Albritton M.S.
Memory Allocation Relational Operators Logical Operators If Statements Switch Statements
Relational Operators
Relational Operators Relational operators > (greater than) < (less than) >= (greater than or equal) <= (less than or equal) Will return a 0 (false) or 1 (true)
Relational Operators int num3 = 3, num5 = 5; printf(“%d\n”,num3<num5); //1 printf(“%d\n”,num3>num5); //0
Equality Operators Equality operators == (equal) != (not equal) Will return a 0 (false) or 1 (true) int num3 = 3, num5 = 5; printf(“%d\n”,num3==num5); //0
Common Error WARNING: a common error is to use the assignment operator (=), instead of the equality operator (==) Still compiles, so it is a difficult bug to find! And it will change the value of the 1st operand int num3 = 3, num5 = 5; printf(“%d\n”,num3=num5); //5
Boolean Operator not (!) !x is the same as 0==x For the C language, zero is false And anything non-zero is true Determines if x is equal to zero, or not equal to zero int zero = 0, num5 = 5; printf(“%d\n”,!zero); //1 printf(“%d\n”,!num5); //0
Example Program See example code at: operators.c
Logical Operators
Logical Operators Logical Operator Symbol AND && OR | | NOT !
Logical Operators AND (&&), OR (||), NOT (!) Evaluated left to right Returns true (1) or false (0)

#### You've reached the end of your free preview.

Want to read all 42 pages?

• Spring '18
• Logic, Equals sign, relational operator