Chapter 4 Flashcards

1
Q

relational operators

A

allow comparisons of numeric and char values and determine whether one is greater than, less than, equal to, or not equal to another.

Ex: num1 > num2; num1 != num2;

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

flag

A

a boolean or integer variable that signals when a condition exists

if (flag ) // same as if (flag == true)
run code;

if (integerFlag) // if 0 = false
if (integerFlag) // if nonzero = true
Ex: salesQuotaMet = 0; // this is an integer flag = 0 = false = sales quota NOT met…
salesQuotaMet = 1 = nonzero = true = sales quota met

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

conditional operator

A

create short expressions that work like if/else statements

expression1 ? expression2 : expression3;

same as
if (expression1) expression2;
else expression3;

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

switch statement

A

lets the value of a variable or an expression determine where the program will branch.

switch (variable or expression) {
case constant1: code; // if variable or expression equals constant 1 run code. No break; so program will include the next line of code
case constant2: code; break; // if variable of expression equals constant 2 run code. contains break which will exit the switch.
default: code; // if variable or expression does not equal any case run this code. no need for break
}

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

Logical Operators

A

connect two or more relational expressions into one or reverse the logic of an expression.
&& AND || OR ! NOT

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

&&

A

The logical AND operator. Takes two expressions as operands and creates an expression that is true only when both subexpressions are true.

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

||

A

The logical OR operator. Takes two expressions as operands and creates an expression that is true when either of the subexpressions are true.

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

!

A

The logical NOT operator. It takes an operand and reverses its truth or falsehood.

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

Precedence and Associativity of Logical Operators

A

High to Low
!
&&
||

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

Menu-driven program

A

allows the user to determine the course of action by selecting it from a list of actions.

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

Validating User Input

A

the process of inspecting data given to a program by the user and determining if it is valid.

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

What is the difference between if/else if statement vs a series of if statements

A

The if/else if statement tests a series of conditions. It is often simpler to test a series of conditions with the if/else if statement than with a set of nested if/else statements. The if/else if statement is more human readable.

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

switch statement with initialization

A

switch (Initialization; IntegerExpression) {
case ConstantExpression: code; break;
}

switch (int value = abs(number); value) {
case 1: code; break;
}

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

nested if statement

A

To test more than one condition, an if statement can be nested inside another if statement.

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

Blocks and Variable Scope

A

the scope of a variable is limited to the block in which it is defined.

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