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.
Image of page 1
Memory Allocation Relational Operators Logical Operators If Statements Switch Statements
Image of page 2
Image of page 3
Relational Operators
Image of page 4
Relational Operators Relational operators > (greater than) < (less than) >= (greater than or equal) <= (less than or equal) Will return a 0 (false) or 1 (true)
Image of page 5
Relational Operators int num3 = 3, num5 = 5; printf(“%d\n”,num3<num5); //1 printf(“%d\n”,num3>num5); //0
Image of page 6
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
Image of page 7
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
Image of page 8
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
Image of page 9
Example Program See example code at: operators.c
Image of page 10
Image of page 11
Logical Operators
Image of page 12
Logical Operators Logical Operator Symbol AND && OR | | NOT !
Image of page 13
Logical Operators AND (&&), OR (||), NOT (!) Evaluated left to right Returns true (1) or false (0)
Image of page 14
Image of page 15

You've reached the end of your free preview.

Want to read all 42 pages?

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

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes