5- boolean algebra, boolean and relational operators, branching constructs Flashcards

1
Q

&&

A

logical “and”, binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

||

A

logical “or”, binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

!

A

logical “not”, unary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

==

A

equal to comparison

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

!=

A

not equal to comparison

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

> =

A

greater than or equal to comparison

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

<=

A

less than or equal to comparison

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Precedence of operators

A

()
++ –
unary + -
* / %
+ -
> < >= <= !=
==
&&
|| !
= compound assignment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

block

A

a sequence of statements enclosed in curly brackets

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Variable scope

A

area in program where a variable can be used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Basic id-statement

A

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;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Programming idiom

A

a common way of accomplishing a simple task
swapping values of two variables with a third is an idiom

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If-else statement

A

syntax
if (expression)
body1
else
body2

semantics
if expression is true then
execute body1 otherwise
execute body2

example
if (v == 0)
cout &laquo_space;“v is 0”;
else
cout &laquo_space;“v is not 0”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Ternary operator

A

operator accepting three operands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Conditional operator

A

used as an abbreviated form of branching

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

boolean-expression ? true-expression : false-expression

A

if boolean-expression is true, then the value of whole expression is true-expression, or false-expression otherwise

17
Q

Switch statement

A

expression of any “countable”
type (int, char)
literal or named constant of
same type as expression

syntax
switch (expression){
case constant:
statements
break;
case constant:
statements
default:
statements
}
semantics
expression is evaluated, execution continues in first matching case
(optional) default matches any expression value
break-statement terminates the switch statement, execution continues with a statement following switch-block
if case does not end with break, execution continues to next case