Comp Quiz two

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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) less than 10 C) nothing D) no output, syntax error

A

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

A

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

A

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) and B) not C) or D) none of the above

A

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

A

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

A

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

B

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

B

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) 0 B) run-time error, no output C) other is even D) other is odd

B

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

B

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

B

What is wrong with the following switch statement? int ans; printf("Type y for yes on 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) There are no break statements on 2 cases. B) ans is an int. C) break; is illegal syntax. D) nothing

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

Given the following enumerated 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) 8 C) 7 D) 6 E) unknown

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) 25 B) 35 C) 0 D) 15 E) 40

C

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

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

C

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) what the loop does C) if the loop is in a function D) the minimum number of iterations of the loop

C

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

D

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

D

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

D

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

D

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) (2 <= number && number <= 5) B) (2 <= num <= 5) C) (2 > number && number > 5) D) (number < 2 || number > 5) E) (2 < 5 < number)

D

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)

D

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

D

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

D

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

D

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

E

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

E

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

E

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

E

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

F

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

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

F

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

LF

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

T

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

T

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

T

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

default statement

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

do while

A switch statement variable must be ________.

integer type

Each repetition of a loop body is called ________.

iteration

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

local

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

numerator

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

off by one

The compiler always pairs an else with ________.

the closest if statement without an (else)

A compound statement that contains variable declarations is called a ________

block

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

boolean


संबंधित स्टडी सेट्स

Chapter 37 (Transport Operations)

View Set

Endocrine Disorders Practice Questions

View Set

Air Carrier Operations Chapter 1 quiz

View Set

ECON 182 Microeconomics - Chapter 10 & 11 -Chapter Readings

View Set

Fluid & Electrolyte Balance Application Exam

View Set

Unit 5 part 1- rotational kinematics—-rotational inertia

View Set

Intro to Business 1100- Module 2

View Set

Gene regulation in eukaryotes: transcriptional regulation

View Set