Computing 1: Homework Packet #2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

B

Which of the following symbols has the highest precedence? A. || B. ++ C. && D. -

Boolean

A ____ expression is an expression that can be thought of as being true or false

do-while

A ____ loop always executes the loop body at least once, regardless of the loop condition.

F

A boolean expression may evaluate to more than 2 values. (T/F)

F

A break statement in a switch stops your program. (T/F)

Block

A compound statement that contains variable declaration is called a ____.

Off-by-one

A loop that iterates one too many or one too few times is said to be ____.

T

A semicolon by itself is a valid C statement. (T/F)

an integer type (int, char, enum)

A switch statement variable must be ____.

an iteration

Each repetition of a loop body is called ____.

F

The break statement causes all loops to exit. (T/F)

F

All nested if-else statements can be converted into switch statements. (T/F)

T

All switch statements can be converted into nested if-else statements. (T/F)

C

Given the following code, what is the final value of i? int i, j; for(i = 0; i < 4; j++) { for(j = 0; j < 3; j++) { if(i == 2) break; } } A. 5 B. 0 C. 4 D. 3

A

Given the following code, what is the final value of i? int i; for(i = 0; i <= 4; i++) { printf("%d\n", i); } A. 5 B. 3 C. 0 D. 4

D

Given the following data type definition, what is the value of SAT? enum MyType{SUN = 3, MON = 1, TUE = 3, WED, THUR, FRI, SAT, NumDays}; A. 5 B. 6 C. 8 D. 7 E. unknown

C

Given the following enumerated data type definition, what is the value of SAT? enum MyType{SUN, MON, TUE, WED, THUR, FRI, SAT, NumDays}; A. 5 B. 7 C. 6 D. 8 E. unknown

D

How many times is "Hi" printed to the screen? int i; for(i = 0; i < 14; i++); printf("Hi\n"); A. 13 B. 14 C. 15 D. 1

C

If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0? int other = 3, myInt; if(myInt != 0 && other % myInt != 0) printf("other is odd\n"); else printf("other is even\n"); A. other is odd B. other is even C. run-time error, no output D. 0

A

If x is 0, what is the value of the boolean expression (!x == 0)? A. 0 B. syntax error C. unable to determine D. 1

C

If x is 42, what is the value of the boolean expression (!x == 0)? A. unable to determine B. 0 C. 1 D. syntax error

A

If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition? A. (number < 2 || number > 5) B. (2 <= num <= 5) C. (2 > number && number > 5) D. (2 <= number && number <= 5) E. (2 < 5 < number)

B

If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test? A. (x < 10 && y > 3) B. (x >= 10 || y <= 3) C. (x >= 10 && y <= 3) D. (x > 10 || y < 3)

F

In an enumerated data type, different constants may not have the same value. (T/F)

F

It is illegal to make function calls inside a switch statement. (T/F)

Default

The code following the ____ case is executed if none of the other cases are matched in a switch statement.

The nearest previous if (not already paired with an else)

The compiler always pairs an else with ____.

B

What is the value of x after the following code executes? int x = 10; if(x++ > 10) { x = 13; } A. 9 B. 11 C. 13 D. 10

D

What is wrong with the following for loop? int i; for(i = 0; i < 10; i --) { printf("Hello\n"); } A. off-by-one error B. cannot use a for-loop for this C. i is not initialized D. infinite loop

lf

The format specifier used to tell scanf to expect a double precision floating point number is a percent sign followed by the character(s) ____.

Local

Variables defined inside a set of braces are said to be ____ to that block of code.

A

What is the output of the following code fragment if x is 15? if(x < 20) if(x < 10) printf("less than 10\n"); else printf("large\n); A. large B. nothing C. no output, syntax error D. less than 10

C

What is the output of the following code fragment? int i = 5; switch(i) { case 0: i = 15;break; case 1: i = 25;break; case 2: i = 35;break; case 3: i = 40; default: i = 0; } printf("%d\n", i); A. 15 B. 25 C. 0 D. 35

B

What is the output of the following code fragment? int x = 0; { int x = 13; printf("%d", x); } printf("%d\n", x); A. 13,13 B. 13,0 C. 0,13 D. Nothing, there is a syntax error.

D

What is the output of the following code fragment? { int x = 13; printf("%d\n", x); A. 0, 13 B. 13, 13 C. 13, 0 D. Nothing, there is a syntax error

A

What is the value of the following boolean expression? (1 && (4/3 || !(6))) A. 1 B. false C. illegal syntax D. 0

C

What is the value of x after the following code executes? int x = 10; if( ++x > 10) { x = 13; } A. 9 B. 11 C. 13 D. 10

B

What is wrong with the following switch statement? int ans; printf("Type y for yes or n for no \n"); scanf("%d", &ans); switch (ans) { case 'y': case 'Y': printf("You said yes\n"); break; case 'n': case 'N': printf("You said no \n"); break; default: printf("invalid answer \n"); } A. nothing B. ans is an int C. break; is illegal syntax. D. There are no break statements on 2 cases.

E

When testing a program with a loop, which of the following tests should be done? A. one less than the maximum number of iterations B. no iterations of the loops C. the maximum number of iterations D. one more than the maximum number of iterations E. A, B, and C

C

Which boolean operation is described by the following table? A B Operation True True True True False False False True False False False False A. or B. not C. and D. none of the above

B

Which boolean operation is described by the following table? A B Operation True True True True False True False True True False False False A. and B. or C. not D. none of the above

B

Which loop structure always executes at least once? A. while B. do-while C. for D. sentinel

E

Which of the following are allowed in the third section of the for loop statement? A. i-- B. printf("Hello\n"); C. i += 2 D. i++ E. all of the above

C

Which of the following are equivalent to (!(x < 15 && y >= 3))? A. (x > 15 || y < 3) B. (x >= 15 && y < 3) C. (x >= 15 || y < 3) D. (x > 15 && y <= 3) E. B and C

D

Which of the following are valid case statements in a switch? A. case 'ab': B. case x < 4: C. case 1.5: D. case 1:

D

Which of the following boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)? A. (2 <= x <= 15) B. (2 <= x || x <= 15) C. (x <= 15 || x >= 2) D. (x >= 2 && x <= 15)

E

Which of the following data types can be used in a switch controlling expression? A. char B. enum C. double D. int E. A, B, and D

E

Which of the following data types may be used in a switch statement? A. enum B. char C. long D. int E. all of the above

B

Which of the following is not a good reason for choosing a certain loop control (while, do-while, or for loop for example)? A. the condition for ending the loop B. if the loop is in a function C. what the loop does D. the minimum number of iterations of the loop

Enumerated data type

____ is a type whose values are defined by a list of constants of type int.


Ensembles d'études connexes

AP Classroom for Chemical Thermodynamics

View Set

The Four Magical Questions of Application 🦄

View Set

2 - 200-201 https://ccnasec.com/

View Set

Stress Management: Chapter 4 - Mind/Body Connection

View Set

Missouri State University Theatre 101 Foster FINAL

View Set

GCSE Identifying Rocks and Textures under the Microscope

View Set

Chapter 25 Study Guide - The Immortal Life of Henrietta Lacks

View Set