11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

48 Part I: Introduction to C++ Programmingdecisions. (By the same token, that same property makes a computer lookreally stupid when the program makes the wrong decision.) Making decisions,right or wrong, requires the use of logical operators.Using the Simple Logical OperatorsThe simple logical operators, shown in Table 4-1, evaluate to true or false.Table 4-1OperatorMeaningSimple Operators Representing Daily Logic== Equality; true if the left-hand argument has the same value asthe right!= Inequality; opposite of equality>, < Greater than, less than; true if the left-hand argument is greaterthan or less than the right-hand argument>=, or== is true, OR either < or == is true&&AND; true if both the left-and right-hand arguments are true|| OR; true if either the left-or the right-hand argument is true! NOT; true if its argument is falseThe first six entries in Table 4-1 are comparison operators. The equality operatoris used to compare two numbers. For example, the following is true if thevalue of n is 0, and is false otherwise:n == 0;Looks can be deceiving. Don’t confuse the equality operator (==) with theassignment operator (=). Not only is this a common mistake, but it’s a mistakethat the C++ compiler generally cannot catch — that makes it more thantwice as bad.n = 0; // programmer meant to say n == 0The greater-than (>) and less-than (

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!