CS 159 Lab 6 True/False

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/29

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

30 Terms

1
New cards

A piece of data is called logical if it conveys the idea of true or false.

True

2
New cards

C programmers use other types, such as integers, to represent logical data.

True

3
New cards

If a data value is zero it is considered false, but any non-zero value is considered true.

True

4
New cards

The logical AND (&&) operator is only true when both operands are true.

True

5
New cards

The logical OR (||) operator is true only when exactly one of its operands is true.

False - true if at least one is true (or both)

6
New cards

The AND and OR operator share the same level of operator precedence.

False - AND has higher precedence

7
New cards

The short-circuit method of evaluating logical expressions will stop evaluating the current expression as soon as the result can be determined.

True

8
New cards

The complement of the equal operator is the not equal operator.

True

9
New cards

The complement of the less than operator is the greater than operator.

False

10
New cards

When attempting to print the result of a logical expression that is true as an integer the result will always be 1.

True

11
New cards

The logical expression of an if...else construct must be enclosed in parentheses.

True

12
New cards

There is no semi-colon that follows the logical expression of an if...else construct.

True

13
New cards

The statements found inside of an if...else may be any statement, including another if...else construct.

True

14
New cards

The expressions if(a != 0) and if(!a) are complements.

True

15
New cards

The expressions if(a == 0) and if(a) are complements.

True

16
New cards

The dangling else logical error can be corrected by indenting the if and else the same number of spaces.

False - program automatically pairs dangling else to the most recent if statement, so braces are needed to specify the true meaning (indenting doesn’t help)

17
New cards

The conditional expression has three operands and a two-token operator.

True - tokens are ? and :

18
New cards

Conditional expressions cannot be nested as the resulting code becomes too complex.

False - they CAN be nested, but not recommended (because too complex)

19
New cards

3 && -3 && 10 && -10

True

20
New cards

3 || -3 || 10 || -10

True

21
New cards

3 || 6 && 0

True - && expression evaluated first

22
New cards

3 == 4 || 6 || 8

True

23
New cards

3 == 3 && -1 && 1

True

24
New cards

6 % 2 || 7 % 2

True

25
New cards

The following two logical expressions are equivalent for all integer (int) values of x:

!(x < 10) and x >= 10

True

26
New cards

The following two logical expressions are equivalent for all non-negative integer (int) values of x:

x % 2 and x % 2 != 0

True

27
New cards

The complement of

x > 0 && x < 10 || y + 2 == 0

is

x <= 0 || x >= 10 && y + 2 != 0

False I think - precedence?

28
New cards

The compiler will issue a warning when an assignment operator rather than the equality operator is used as the logical expression of an if condition.

True (probably)

29
New cards

It is a course standard to make use of { and } with all if-else constructs.

True

30
New cards

It is a course standard to indent all code within the body of a selection construct two additional spaces.

True