Packet 2 (Exam 1)

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

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) 4 D) 0

a

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

a

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

a

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

a

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

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 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) (2 <= x <= 15) D) (x<= 15 || x >= 2)

a

A switch statement variable must be ________.

an integer type (int, char, enum etc)

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) 6 C) 7 D) 8 E) unknown

b

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

b

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

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

b

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

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

b

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

b

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

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) 14 C) 1 D) 13

c

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

c

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

c

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)

c

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

c

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) nothing C) ans is an int. D) break; is illegal syntax.

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 are valid case statements in a switch? A) case x < 4: B) case 'ab': C) case 1: D) case 1.5:

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) 5 B) 0 C) 3 D) 4

d

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) 8 B) 5 C) 6 D) 7 E) unknown

d

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

d

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

d

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

d

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

default

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

do-while

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 += 2 B) printf("Hello\n"); C) i -- D) i ++ E) all of the above

e

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

e

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

e

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

enumerated data type

A boolean expression may evaluate to more than 2 values.

false

A break statement in a switch stops your program.

false

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

false

In an enumerated data type, different constants may not have the same value.

false

It is illegal to make function calls inside a switch statement.

false

The break statement causes all loops to exit.

false

Each repetition of a loop body is called ________.

iteration

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

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

local

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 nearest previous if not already paired with an else

A semicolon by itself is a valid C statement.

true

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

true


Ensembles d'études connexes

Chapter 13 Reformation and Religious Wars, 1500-1600

View Set

Lecture #1: Seven Secrets for Successful Speaking

View Set

MKT Exam 2 Concept Check (ch.8-13&19-20)

View Set

Chapter 60: Introduction to the Musculoskeletal System

View Set

Physiology Final Exam Review Questions

View Set

Age of Opportunity: Ch.(s) 3 - 4

View Set