A(n) ________ operator determines whether a specific relationship exists between two values.

Relational operators have left to right associativity. Left to right associativity means that when two operators of same precedence are adjacent, the left most operator is evaluated first.

Relational OperatorsMeaning>Greater than=Greater than or equal to<=Less than or equal to==Equal to!=Not equal to

Relational Expression Examples

x > y

x == y

Note: It can be easy to forget that equal to is “==” and not “=” which is assignment.  In many cases, the compiler won’t note this as an error because x==y and x=y are both valid expressions.

What is the result of a relational expression?

Relational expressions are Boolean expressions and thus are equal to either true or false.

How a program treats true and false

C++ programs store true and false in memory as numbers.

false is stored as 0

true is stored as 1

Relational operator precedence and relationship to the other operators

Note how the relational operators rank in precedence to the mathematical and assignment operators. Also, note that the less than/greater than operators have higher precedence than the equal/not equal relational operators.

Precedence highest to lowest( )*, /, %+, ->, >=, <, <=relational==, !=relational=, *=, /=, %=, +=, -=

An example showing precedence

Since relational expressions are Boolean expressions, I have assigned the results of the expression to a bool data type variable. As noted in the example, programmers often enclose relational expressions in parentheses to improve readability.

Instructions Write the MOST CORRECT answer for the following questions in the space provided. For example: If “A” and “C” are both correct, and “D” is “both A and C”, then answering “D” will get you credit. Answering “A” or “C” will get you NO credit.

1)

2)

3)

What operators determine whether a specific relationship exists between two values?

C A.

Arithmetic operators

B.

Logical operators

C.

Relational operators

D.

Combination operators

E.

Ternary operators

What executes statements only when a certain condition is met?

B A.

Sequence structure

B.

Decision structure

C.

Logical structure

D.

Execution structure

E.

Relational structure

What type of expression is either true or false?

D A.

Arithmetic expression

B.

Loop expression

C.

Initialization expression

D.

Boolean expression

E.

None of the above

Page 1

4)

5)

6)

7)

A

What is enclosing one structure inside of another?

A.

Nesting

B.

Enclosure

C.

Zoning

D.

Looping

E.

Inserting

What operators either change the value of a boolean expression or combine two boolean expressions.

B A.

Arithmetic operators

B.

Logical operators

C.

Relational operators

D.

Combination operators

E.

Ternary operators

If both x and y are string variables x == y compares what?

D A.

The characters in their strings alphabetically

B.

The Unicode values of the characters in their strings

C.

The names of the variables

D.

The references the variables hold

E.

The length of the strings

What class does the Java API provide that allows us to format a floating-point number in a specific way?

E A.

FloatFormat

B.

NumberFormat

C.

JavaFormat

D.

DoubleFormat

E.

DecimalFormat

Page 2

8)

9)

10)

11)

A

What is a control structure that causes a statement or block of statements to repeat? A.

Looping structure

B.

Decision structure

C.

Sequential structure

D.

Switch structure

E.

Arithmetic structure

What is a loop that does not have a way of terminating its iteration, and thus will repeat indefinitely?

E A.

Indefinite loop

B.

Forever loop

C.

Boundless loop

D.

Unending loop

E.

Infinite loop

In Java, the for loop is what kind of loop?

C A.

An infinite loop

B.

A conditionally-controlled loop

C.

A count-controlled loop

D.

A sentinel controlled loop

E.

Both C and D

What expression is NOT an element of a for loop?

C A.

Initialization expression

B.

Test expression

C.

Iteration expression

D.

Update expression

Page 3

12)

13)

14) `

15)

Which of the following is NOT a pretest loop?

B A.

while loop

B.

do-while loop

C.

for loop

D.

Both B and C

E.

All are pretest loops

What is a variable that keeps track of a running total?

E A.

A collection variable

B.

A sentinel variable

C.

An assembly variable

D.

An agglomeration variable

E.

An accumulator variable

What is a special value that cannot be mistaken for normal input that signals that a loop should terminate?

What operators determine whether a specific relationship exists between two values?

Relational operators are important for making decisions. They allow us compare numeric and char (chars are treated like numbers in C++) values to determine if one is greater than, less than, equal to, or not equal to another. Relational operators are binary meaning they require two operands.

Which operator is used to determine the relationship between two or more operands?

In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality (e.g., 5 = 5) and inequalities (e.g., 4 ≥ 3).

What type of operator can be used to determine whether?

Introduction to Programming 04.

Which operator is used to determine that the operands are not exactly of the same value?

The inequality operator != returns true if its operands are not equal, false otherwise. For the operands of the built-in types, the expression x !=