Karteikarten
Computing I Packet 2
Karten in diesem Stapel (50)
- 1A _____ expression is an expression that can be thought of as being true or false.boolean
- 2A loop that iterates one too many or one too few times is said to be _____.off by one
- 3A compound statment that contains variable declarations is called a _____.block
- 4Each repetition of a loop body is called _____.iteration
- 5The format specifier used to tell scanf to expect a double precision floating point number is a percent sign followed by the character(s) _____.lf
- 6The compiler always pairs an else withthe nearest unpaired if
- 7A switch statement variable must be _____.int, char, enum
- 8_____ is a type whose values are defined by a list of constants of type intenum
- 9Variables defined inside a set of braces are said to be _____ to that block of code.local
- 10A _____ loop always executes the loop body at least once, regardless of the loop condition.do while
- 11The code following the _____ case is executed if none of the other cases are matched in a switch statement.default
- 12What is the value of x after the following code executes? int x = 10; if (++x > 10) { x = 13; }13 (if 11 > 10)
- 13If x is 0, what is the value of the boolean expression (!x == 0)?0
- 14If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test?(x >= 10 || y <= 3)
- 15If x is 42, what is the value of the boolean expression (!x == 0)?1
- 16Which boolean operation is described by the following table? T T T T F T F T T F F For
- 17Which of the following boolean expressions tests to see if x is between 2 and 15 (including 2 and 15)?(x >= 2 && x <= 15)
- 18What 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);0
- 19If a programming language does not have 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"run-time error, no output
- 20Which of the following data types may be used in a switch statement? a. char b. int c. enum d. long e. all of the abovee. all of the above
- 21Given 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; } }4
- 22Given the following code, what is the final value of i? int i; for (i = 0; i <= 4; i++) { printf("%d\n", i); }5
- 23What is wrong with the following for loop? int i; for (i = 0; i < 10; i--) { printf("Hello\n"); }infinite loop
- 24Given 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};7
- 25Which of the following data types can be used in a switch controlling expression? a. int b. enum c. double d. char e. a, b, and de. a, b, and d
- 26What is the output of the following code fragment? { int x = 13; printf("%d\n", x); } printf("%d\n", x);Nothing, there is a syntax error
- 27Which of the following are valid case statements in a switch? a. case x < 4: b. case 1.5: c. case 1: d. case'ab':c. case 1:
- 28Which 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 Cc. (x >= 15 || y < 3)
- 29Which loop structure always executes at least once?do while
- 30How any 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");1 (SNAKE semicolon)
- 31When 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 loop c. the maximum number of iterations d. one more than the maximum number of iterations e. A, B, and Ce. A, B, and C
- 32Which 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 loopc. if the loop is in a function
- 33Which boolean operation is described by the following table? T T T T F F F T F F F Fand
- 34Wha 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"); }ans is an int
- 35Which of the following symbols has the highest precedence? a. - b. && c. || d. ++NO ANSWER, but put
d. ++ - 36What is the value of the following boolean expression? (1 && (4/3 || !(6)))1
- 37Which of the following are allowed in the third section of the for loop statement? a. printf("Hello\n"); b. i += 2 c. i++ d. i-- e. all of the abovee. all of the above
- 38If 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?(number < 2 || number > 5)
- 39What is the value of x after the following code executes? int x = 10; if (x++ > 10) { x = 13; }11 (if 10 > 10)
- 40Given the following enumerated data type definition, what is the value of SAT? enum MyType{SUN, MON, TUE, WED, THUR, FRI, SAT, NumDays};6
- 41What is the output of the following code fragment? int x = 0; { int x = 13; printf("%d,", x); } printf("%d", x);13, 0
- 42What 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");large
- 43T or F All switch statements can be converted into nested if else statements.T
- 44T or F The break statement casuses all loops to exit.F
- 45T or F All nested if else statements can be converted into switch statements.F
- 46T or F It is illegal to make function calls inside a switch statement.F
- 47T or F In an enumerated data type, different constants may not have the same value.F
- 48T or F A boolean expression may evaluate to more than 2 values.F
- 49T or F A break statement in a switch stops your program.F
- 50T or F A semicolon by itself is a valid C statement.T
Informationen
- Beschreibung
- Karteikarten am Computing I Packet 2, erstellt von Vanessa Chen am 05/05/2019.
- Erstellt von
- Vanessa Chen
- Aufrufe
- 0
- Bewertung