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

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

View Full Document Right Arrow Icon
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.
Background image of page 1

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

View Full DocumentRight Arrow Icon
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!
Background image of page 2
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…
Background image of page 3

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

View Full DocumentRight Arrow Icon
#include <stdio.h>
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online