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

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

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

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

View Full DocumentRight Arrow Icon
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;
Background image of page 2
Logical Expressions, IF
Background image of page 3

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

View Full DocumentRight Arrow Icon
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”
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Boolean Algebra Truth table for || (logical “or”) P Q P || Q False False False False True True True False True True True True
Background image of page 6
Boolean Algebra Truth table for ! (logical “not”) P ! P False True True False
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
A Boolean Type C++ contains a type named bool type bool has two symbolic constants
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

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