# IfStmt2 - Notes About Boolean Expressions No boolean type...

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

Notes About Boolean Expressions No boolean type, so boolean expressions evaulate to 0(false) or 1(true). x = (x > y); // is valid. It will set x to 0 or 1. if (x) x++; // is valid. If x isn’t 0, it adds 1 to x. !!5 // is equal to 1 For these reasons, try to use boolean expressions ONLY where they are meant to be used.

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

View Full Document
Short-Circuit Evaluation If the first component is false, the second is never evaluated if (b !=0 && (a/b > 0)) … // If b is zero, we never try to divide by it OR (||) If the first component is true, the second is never evaluated if (age >= 21 || fakeid == 1) … // If you are older than 21, you don’t need to check for the fake!
Block of Statements/ Empty Statement A block of statements ({}) acts as a single statement for syntactic purposes, which is why we use a block for a part of an if statement An empty statement is as follows: ; This is important because if you add a semicolon somewhere, it changes the interpretation of the statement if (b !=0); value = a/b; // Here, the division happens even when b is 0…

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

View Full Document
#include <stdio.h>
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

IfStmt2 - Notes About Boolean Expressions No boolean type...

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

View Full Document
Ask a homework question - tutors are online