5- boolean algebra, boolean and relational operators, branching constructs Flashcards
&&
logical “and”, binary
||
logical “or”, binary
!
logical “not”, unary
==
equal to comparison
!=
not equal to comparison
> =
greater than or equal to comparison
<=
less than or equal to comparison
Precedence of operators
()
++ –
unary + -
* / %
+ -
> < >= <= !=
==
&&
|| !
= compound assignment
block
a sequence of statements enclosed in curly brackets
Variable scope
area in program where a variable can be used
Basic id-statement
syntax
if (expression) body
semantics: if the expression is true then execute body
body is either a single statement or a block
example 1:
if (v > 0) v = 0;
example 2:
if (v < 0){
v = -v;
i += 1;
}
Programming idiom
a common way of accomplishing a simple task
swapping values of two variables with a third is an idiom
If-else statement
syntax
if (expression)
body1
else
body2
semantics
if expression is true then
execute body1 otherwise
execute body2
example
if (v == 0)
cout «_space;“v is 0”;
else
cout «_space;“v is not 0”;
Ternary operator
operator accepting three operands
Conditional operator
used as an abbreviated form of branching