# L05if - What is the Result and Type of the Following...

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

What is the Result and Type of the Following Expressions? int x=2, y=15; double u=2.0, v=15.0; -x x+y x-y x*v y / x x/y y%x x%y u*v u/v v/u u%v x * u (x+y)*u u /(x-x) x++ u++ u = --x u = x-- u *= ++x; v /= x;

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

View Full Document
Types are these constants legal? .5 5.E 0.5e3 0.5E-3 0.5E-3.5 ‘a’ ‘%’ ‘Ab’ “Ab” are these variable names legal? MyTotal My_Total __MyTotal My Total what does this mean? int mytotal=0; int yourtotal(1); what would be stored in myvar ? int myvar; myvar=2.56; what would be stored in yourvar ? double yourvar; yourvar=5/2;
Logical Expressions, IF

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

View Full Document
Boolean Algebra Logical expressions have the one of two values - true or false A rectangle has three sides. The instructor has a pleasant smile The branch of mathematics that deals with this type of logic is called Boolean algebra Developed by the British mathematician George Boole in the 19th century C++ makes extensive use of Boolean algebra in the form of logical expressions; what is an expression again? Three key logical operators in C++: && - logical “and” || - logical “or” ! - logical “not”
Boolean Algebra Truth tables Lists all combinations of operand values and the result of the operation for each combination truth table for (logical “and’) P Q P Q False False False False True False True False False True True True

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

View Full Document
Boolean Algebra Truth table for || (logical “or”) P Q P || Q False False False False True True True False True True True True
Boolean Algebra Truth table for ! (logical “not”) P ! P False True True False

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

View Full Document
Boolean Algebra Can create complex logical expressions by combining simple logical expressions Example ! (P Q) A truth table can be used to determine when a logical expression is true P Q P Q ! (P Q) False False False True False True False True True False False True True True True False
A Boolean Type C++ contains a type named bool type bool has two symbolic constants

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 27

L05if - What is the Result and Type of the Following...

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

View Full Document
Ask a homework question - tutors are online