COP1220 Quiz 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What values for x cause Branch 1 to execute? If x > 100 : Branch 1 Else If x > 200: Branch 2 a. 100 to 200 b. 100 or larger c. 101 or larger d. 101 to 200

c

Given string str is "Great", which choice has all matching expressions? a.strcmp(str, "Great"), strcmp(str, "great") b.strcmp(str, "Great") c.strcmp(str, "Great"), strcmp(str, "Great!") d.strcmp(str, "Great"), strcmp(str, "great"), strcmp(str, "Great!")

B

What is the relation between a string's length and the string's last index? a.lastIndex == length b.lastIndex == length - 1 c.lastIndex == length + 1 d.lastIndex == length + 2

B

Which input value causes "Goodbye" to be output next? int x; scanf("%d", &x); while (x >= 0) { // Do something scanf("%d", &x); } printf("Goodbye\n"); a.-1 b.0 c.1 d.No such value

A

Which expression for YYY will result in an output of "Pass" only if x is exactly 32? int x; scanf("%d", &x); if(YYY) { printf("Pass"); }else {printf("Fail"); } a.x != 32 b.x == 32 c.x >= 32 d.x <= 32

B

What is the final value of y? int x = 6; int y = 2; if (x < 10) { if (y < 5) { y = y + 1; } else { y = 7; } } else { y = y + 10; } a.3 b.7 c.12 d.13

A

A programmer compares x == y, where x and y are doubles. Many different values are expected for x and y. For values that a programmer expects to be equal, the comparison will _____ . a.always evaluate to true b.always evaluate to false c.sometimes evaluate to true, sometimes to false, depending on the values d.sometimes immediately exit the program, for values that are slightly different

C

For what values of x does the default case execute in the code below? x is declared as an integer. switch (x) { case 2:... break; case 3: ... break; case 4: ... break; default: ... // When does this execute? } a.Only for value 5 b.Only for all values greater than 4 c.Only for values that are not 2, 3, or 4 d.For any value

C

What is the ending value of numItems if myChar = 'X'? switch (myChar) { case 'W': numItems = 1; case 'X': numItems = 2; case 'Y': numItems = 3; case 'Z': numItems = 4;} a.2 b.3 c.4 d.9

C

Given str = "Cat", what is the result of this statement? str[1] = "ab"; a.str is "abt" b.str is "Catab" c.str is "Cab" d.Error: Assigning a character with a string is not allowed

D

What is output, if the input is 3 2 1 0? scanf("%d", &x); while (x > 0) { printf("%d ", 2 * x); } a.6 b.6 4 2 c.6 4 2 0 d.6 6 6 6 6 ... (infinite loop)

D

Which expression for XXX causes the code to output the strings in alphabetical order? (Assume the strings are lowercase) if (XXX) { printf("%s %s\n",firstString, secondString); } else { printf("%s %s\n",secondString, firstString); } a.strcmp(str1, str2) != 0 b.strcmp(str1, str2) == 0 c.strcmp(firstString, secondString) > 0 d.strcmp(firstString, secondString) < 0

D

Which expression for XXX outputs "Modern era" for any year 1980 and later? if (year < 2000) { // Output "Past" } else if (XXX) { // Output "Modern era" } a.year > 1980 b.year >= 1980 c.year >= 2000 d.(No such expression exists)

D

If the input is -5, what is the output? If x less than 0 Put "Low " to output Else if x greater than 0 Put "OK " to output Else if x less than -3 Put "Very low " to output a. Low b. Low Very low c. (Runs, but no output) d. Error: The compiler will complain about a missing else statement

a

A loop should sum all inputs, stopping when the input is 0. If the input is 2 4 6 0, sum should end with 12. What should XXX, YYY, and ZZZ be? Choices are in the form XXX / YYY / ZZZ. int sum; int currVal; XXX; scanf("%d", &currVal); while (YYY) { ZZZ; scanf("%d", &currVal); } a. sum = 0 / currVal != 0 / sum = sum + currVal b. sum = currVal / currVal == 0 / sum = currVal c. sum = 1 / currVal != 0 / sum = sum + 1 d. scanf("%d", &sum) / currVal == 0 / scanf("%d", &sum)

a

Both must be true for a person to ride: (1) At least 5 years old, (2) Taller than 36 inches. Which expression evaluates to true if a person can ride? a. (age >= 5) && (height > 36) b. (age >= 5) || (height > 36) c. (age > 5) && (height <= 36) d. (age > 5) || (height <= 36)

a

Given x = 1, y = 2, and z = 3, how is the expression evaluated? In the choices, items in parentheses are evaluated first.(x == 5) || (y == 2) && (z == 5) a. false OR (true AND false) --> false OR false --> false b. false OR (true AND false) --> false OR true --> true c. (false OR true) AND false --> true AND false --> false d. (false OR true) AND false --> true AND false --> true

a

Given year is positive, which expressions for XXX, YYY, and ZZZ will output the correct range? Choices are in the form XXX / YYY / ZZZ. If XXX: Output "1-100" Else If YYY: Output "101-200" Else If ZZZ: Output "201-300" Else: Output "Other" a. year < 101 / year < 201 / year < 301 b. year > 0 / year > 99 / year > 199 c. year > 0 / year > 100 / year > 200 d. year < 100 / year < 200 / year < 300

a

How is the expression evaluated? ! x - 3 > 0 a. ((!x) - 3) > 0 b. (!(x - 3) > 0 c. (!x) - (3 > 0) d. !((x - 3) > 0)

a

In the following code, which conditions will lead to the booleans continue and needFill to both be true? halfFull = (currentTank > fullTank * .5); full = (currentTank == fullTank); empty = (currentTank == 0); almostEmpty = (currentTank < fullTank * .25) if (full || halfFull) { continue= true; needFill = false; } else if (almostEmpty && !Empty ) { continue = true; needFill = true; } else { continue = false; needfill = true; } a. almostEmpty == true && empty == false b. full == true || halfFull == true c. almostEmpty == true || empty == false d. almostEmpty == true && halfFull == true

a

What does this code do? If x less than y Put x to output Else Put y to output a. Outputs the lesser of the two integers; if they are equal, outputs that integer b. Outputs the lesser of the two integers; if they are equal, outputs nothing c. Outputs the greater of the two integers; if they are equal, outputs that integer d. Outputs the greater of the two integers; if they are equal, outputs nothing

a

What value of x outputs "Junior"? if (x < 56) { // Output "Sophomore" } else if (x > 56) { // Output "Senior" } else { // Output "Junior" } a. Value 56 b. Values 57 or larger c. Values 55 or 57 d. No such value

a

Which XXX and YYY will loop as long as the input is an integer less than 100? Choices are in the form XXX / YYY. scanf("%d", &w); while (XXX) { // Do something YYY; } a. w < 100 / scanf("%d", &w) b. w >= 100 / (nothing) c. w < 100 / (nothing) d. w >= 100 / scanf("%d", &w)

a

Which expression follows the practice of using parentheses to make the intended order of evaluation explicit? x > y && !a == b a. (x > y) && (!a == b) b. (x > (y)) && ((!a == b)) c. ((x > y) && !a == (b)) d. ((x > y)) && ((!a == b))

a

Which expression for YYY outputs "Quarter century!" when the input is 25? int x; scanf("%d", &x); if (YYY) { printf("Nothing special"); } else { printf("Quarter century!"); } a.x != 25 b.x == 25 c.x <> 25 d.x == !25

a

Which expressions for YYY and ZZZ will output "Young" for ages less than 20 and "Young but not too young" for ages between 10 and 20?int u; scanf("%d", &u); if (YYY) { printf("Young"); } if (ZZZ) { printf(" but not too young"); } a.YYY: u < 20 ZZZ: u > 10 b.YYY: u < 20 ZZZ: u < 10 c.YYY: u > 20 ZZZ: u < 10 d.YYY: u > 20 ZZZ: u > 10

a

Which if branch executes when an account lacks funds and has not been used recently? hasFunds and recentlyUsed are booleans and have their intuitive meanings. a. if (!hasFunds && !recentlyUsed) b. if (!hasFunds && recentlyUsed) c. if (hasFunds && !recentlyUsed) d. if (hasFunds && recentlyUsed)

a

Which is an essential feature of a while loop having the following form? while (LoopExpression) { LoopBody } a. The LoopExpression should be affected by the LoopBody b. The LoopExpression should not be affected by the LoopBody c. The LoopBody should get user input d. The LoopBody should update at least two variables

a

Which is the simplest expression that is true only when myChar is among a-z or A-Z? a. isalpha(myChar) b. isalpha(tolower(myChar)) c. isalpha(myChar) && !isspace(myChar) d. isalpha(tolower(myChar)) || isalpha(toupper(myChar))

a

Which is true about incremental program development? a.All programmers, regardless of experience, benefit from incremental development b.Bugs are more likely to go unnoticed as more code is added c.Programmers don't have to compile code as often when developing incrementally d.The only benefit of incremental development is readable code

a

Which value of x results in short circuit evaluation, causing y < 4 to not be evaluated? (x >= 7) && (y < 4) a. 6 b. 7 c. 8 d. No such value

a

Which value of z will cause boolean x to short circuit to false even if y == 10? x = (z < 21) && (y == 10) a. z = 22 b. z = 12 c. z = 20 d. z = -5

a

Why should programmers avoid making the following comparison with double x? x == 0.3 a. Because 0.3 may not be exactly represented as 0.3 b. Because doubles should not be compared with integers c. Because variables should not be compared with literals d.Because the 0.3 should come first: 0.3 == x

a

According to the following expression, what is z if x is 32 and y is 25? z = (x <= y) ? y : x + y; a. 25 b. 57 c. 32 d. 7

b

A loop should output 1 to n. If n is 5, the output is 12345. What should XXX and YYY be? Choices are in the form XXX / YYY. scanf("%d", &n); for (XXX; i++) { printf("%d", YYY); } a.i = 0; i < n / i; b.i = 0; i < n / i + 1; c.i = 1; i < n / i; d.i = 1; i < n / i + 1;

b

A programmer must write a 500 line program. Which is most likely the best approach? a. Write 1 line, run and debug, write 1 more line, run and debug, repeat b. Write 10-20 lines, run and debug, write 10-20 more lines, run and debug, repeat c. Write 250 lines, run and debug, write 250 lines, run and debug d. Write 500 lines, run and debug

b

A restaurant gives a discount for children under 10. They also give the discount for adults over 55. Which expression evaluates to true if a discount should be given? a. (age < 10) && (age > 55) b. (age < 10) || (age > 55) c. (age >= 10) && (age <= 55) d. (age >= 10) || (age <= 55)

b

For the given pseudocode, which XXX and YYY will output the number of times that 10 is input (stopping when 0 is input)? Choices are in the form XXX / YYY. count = 0 val = Get next input While val is not 0 If val == 10 XXX Else YYY val = Get next input Put count to output a. count = count + 1 / count = 0 b. count = count + 1 / (nothing) c. count = count + val / (nothing) d. count = count + val / count = 0

b

For the string "on time", what character is at index 3? a. (Space) b. t c. i d. m

b

Given string str1 and string str2, which expression is true? str1 = "Flat"; str2 = "Last"; a. strcmp(str1, str2) == 0 b. strcmp(str1, str2) < 0 c. strcmp(str1, str2) > 0 d. (Comparison not possible)

b

Given userStr = "Doghouse", what is the ending value of char x? x = tolower(userStr[2]); a. G b. g c. (Space) d. Error: Compiler complains about converting an already-lowercase letter

b

How many times does the while loop execute for the given input values of -1 4 0 9? userNum = 3; while (userNum > 0) { // Do something // Get userNum from input } a. 0 b. 1 c. 2 d. 3

b

How many times will the loop iterate, if the input is 105 107 99 103?scanf("%d", &x); while (x > 100) { // Do something scanf("%d", &x); } a. 1 b. 2 c. 3 d. 4

b

How many x's will be output? Assume row and col are integers. for (row = 0; row < 2; ++row) { printf("x"); for (col = 0; col < 3; ++col) { // Do something } } a. 1 b. 2 c. 3 d. 6

b

If the input is 5, what is the output? int x; int z=0; scanf("%d", &x); if(x > 9) { z = 3; } z = z + 1; printf("%d",z); a. 0 b. 1 c. 3 d. 4

b

If the input is 7, what is the output? If x less than 10 Put "Tiny " to output Else Put "Not tiny " to output If x less than 100 Put "Small " to output a. Tiny b. Tiny Small c. Not tiny Small d. (No output)

b

If the input sets int x with 5 and int y with 7, what is the ending value of z? z is declared as a boolean. z = (x > y); a. True b. False c. Error: No value assigned to z due to a runtime error d. Error: No value assigned to z due to a syntax error

b

The difference threshold indicating that floating-point numbers are equal is often called what? a. Double b. Epsilon c. Difference d. Threshold

b

The program should determine the largest integer seen. What should XXX be, if the input values are any integers (negative and non-negative)? All variables are integers and have unknown initial values. for (i = 0; i < 10; ++i) { scanf("%d", &currValue); if (i == 0) { // First iteration XXX; } else if (currValue > maxSoFar) { maxSoFar = currValue; } } a. maxSoFar = 0 b. maxSoFar = currValue c. currValue = 0 d. currValue = maxSoFar

b

The program should output even values between -10 and 10 (inclusive), so -10 -8 ... 8 10. What should XXX be? for (XXX) { printf("%d \n", &i); } a. i = -10; i < 10; i = i + 2 b. i = -10; i <= 10; i = i + 2 c. i = -10; (i * 2) < 10; ++i d. i = -10; (i * 2) <= 10; ++i

b

To quit, a user types 'q'. To continue, a user types any other key. Which expression evaluates to true if a user should continue? a. key == 'q' b. !(key == 'q') c. (!key) == 'q' d. key == (!'q')

b

What is output, if the input is 3 2 4 5? All variables are integers. scanf("%d", &num); for (i = 0; i < num; ++i) { scanf("%d", &curr); printf("%d", curr); } a. 24 b. 245 c. 324 d. 3245

b

What is the ending value of len? str = "Mid-wife "; len = strlen(str); a. 7 b. 9 c. 8 d. 11

b

What is the ending value of userString? (Note the question asks about userString, not about x). userString = "FaceBook"; x = tolower(userString[4]); a. Facebook b. FaceBook c. Faceook d. b

b

What is the output, if n is 3? for (int i = 1; i <= n; ++i) { int factorial = 1; factorial = factorial * i; printf("%d ", factorial); } a.1 1 2001 b.1 2 2003 c.1 2 2006 d.Error: Cannot use the loop variable i inside the for loop

b

Which XXX causes every character in string inputWord to be output?for (XXX) { printf("%c\n" &inputWord[i]); } a. i = 0; i < strlen(inputWord) - 1); ++i b. i = 0; i < strlen(inputWord); ++i c. i = 0; i < strlen(inputWord) + 1); ++i d. i = 0; i <= strlen(inputWord); ++i

b

Which XXX will output only values up to 3? i is an int. for (i = 1; i < 10; i++) { printf("%d ", i); XXX { break; } } a. if (i != 3) b. if (i == 3) c. if (i != 4) d. if (i == 4)

b

Which expression evaluates to false if x is 0 and y is 10? a. (x == 0) && (y == 10) b. (x == 0) && (y == 20) c. (x == 0) || (y == 10) d. (x == 0) || (y == 20)

b

Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"? a.if (val > 0) { printf("Non-negative"); } else { printf("Negative"); } b.if (val >= 0) { printf("Non-negative"); } else { printf("Negative"); } c.if (val < 0) { printf("Non-negative"); } else { printf("Negative"); } d.if (val <= 0) { printf("Negative"); }else { printf("Non-negative"); }

b

A restaurant serves breakfast before 11 am, after which they serve lunch. Which expression for XXX outputs the correct string for any time? Variable time ranges from 0 to 23 (e.g., 13 means 1 pm). mealString = XXX; // Output mealString a. (time > 11) ? "Breakfast" : "Lunch" b. (time == 11) ? "Breakfast" : "Lunch" c. (time < 11) ? "Breakfast" : "Lunch" d. (time != 11) ? "Breakfast" : "Lunch"

c

For the given pseudocode, which XXX and YYY will output the sum of the input integers (stopping when -1 is input)? Choices are in the form XXX / YYY. val = Get next input XXX While val is not -1 YYY val = Get next input Put sum to output a.sum = val / sum = val b.sum = val / sum = sum + val c.sum = 0 / sum = sum + val d.sum = 0 / sum = val

c

For the string "Orange", what character is at index 3? a. r b. a c. n d. g

c

For what values of x will "Medium" be output?If x > 40: Output "Large" Else If x > 20: Output "Medium" Else If x > 10: Output "Small" a. Any x smaller than 20 b. Any x larger than 40 c. Any x from 21 to 40 d. Any x from 10 to 40

c

Given string str1 and string str2, which expression is true? str1 = "Hi"; str2 = "Hello"; a.strcmp(str1, str2) == 0 b.strcmp(str1, str2) < 0 c.strcmp(str1, str2) > 0 d.(Comparison not possible)

c

Given the following code, what value of numCorrect outputs "You answered all but one question correctly!"? int numCorrect; switch(numCorrect) { case 0: printf("You didn't answer any questions correctly.\n"); break; case 1: printf("You answered only one question correctly.\n"); break; case 2: printf("You answered only two questions correctly.\n"); break; case 3: printf("You answered all but one question correctly!\n"); break; case 4: printf("You answered all four questions correctly!\n"); break; default: printf("Please check your input. There are only four questions.\n"); break; } a.1 b.2 c.3 d.4

c

If the input is 5, what is the output? int x; scanf("%d", &x); if (x < 10) { printf("Live "); } else if (x < 20) { printf("long "); } else if (x < 30) { printf( "and "); } printf("prosper!"); a. Live b. Live long c. Live prosper! d. Error: The compiler will complain about a missing else statement

c

What is output, if userVal is 5? int x; x = 100; if (userVal != 0) { int tmpVal; tmpVal = x / userVal; printf("%d", tmpVal); } a. 0 b. 5 c. 20 d. Error: The compiler generates an error

c

What is the ending value of sum, if the input is 2 5 7 3? All variables are integers. scanf("%d", &x); sum = 0; for (i = 0; i < x; ++i) { scanf("%d", &currValue); sum += currValue; } a. 5 b. 10 c. 12 d. 15

c

What is the ending value of y if x is 50? y and x are ints. y = (x < 21) ? 100 : x; a. 'x' b. 21 c. 50 d. 100

c

What is the final value of y? int x = 77; int y = 4; if (x == 77) { y = y + 1; } if (x < 100) { y = y + 1; } if (x > 77) { y = y + 1; } y = y + 1; a. 5 b. 6 c. 7 d. 8

c

What is the output if count is 4? for (i = count; i > 0; --i) { // Output i } a. 4 b. 321 c. 4321 d. 43210

c

What is the output if the input is "Yes", "No", "Yes", "Maybe"? char response[10] = ""; scanf("%s", response); while (strcmp(response, "Maybe") != 0) { if (strcmp(response, "Yes") == 0) { printf("Wrong "); } else { printf("%s ", response); } scanf("%s", response); } a.Yes No Yes b.Wrong No Wrong Maybe c.Wrong No Wrong d.Yes No Yes Maybe

c

What is the output? int n; for (n = 0; n < 10; n = n + 3) { printf("%d ", n); } a.0 1 2 3 4 5 6 7 8 9 b.1 4 7 10 c.0 3 6 9 d.0 3 6 9 12

c

What is the output? int num = 10; while (num <= 15) {printf("%d ", num); if (num == 12) { break; } ++num; } printf("Done"); a. 10 Done b. 10 11 Done c. 10 11 12 Done d. 10 11 12 13 14 15 Done

c

What is the output? int x = 18; while (x > 0) { // Output x and a space x = x / 3; } a.6 2 b.6 2 0 c.18 6 2 d.18 6 2 0

c

What is the output? j and k are ints. for (j = 0; j < 2; ++j) { for (k = 0; k < 4; ++k) { if (k == 2) {break; } printf("%d%d ", j, k); } } a. 00 01 02 b. 00 01 02 03 c. 00 01 10 11 d. 00 01 02 10 11 12

c

Which YYY outputs the string in reverse? Ex: If the input is "Oh my", the output is "ym hO". int i;string str; scanf("%s", str); for (YYY) { printf("%c", str[i]); } a. i = str.length(); i < 0; --i b. i = str.length(); i > 0; --i c. i = str.length() - 1; i >= 0; --i d. i = str.length() + 1; i > 0; --i

c

Which expression best determines if double variable x is 74.7? a.fabs (x - 74.7) != 0.0001 b.fabs (x - 74.7) > 0.0001 c.fabs (x - 74.7) < 0.0001 d.fabs (x - 74.7) == 0.0001

c

Which expression correctly evaluates 13 < num < 30? a.(num < 13) && (num < 30) b.(num < 13) || (num < 30) c.(num > 13) && (num < 30) d.(num > 13) || (num < 30)

c

Which expressions for XXX, YYY, and ZZZ output "Great job" for scores above 90, and "Nice try" otherwise? Choices are in the form XXX / YYY / ZZZ. int score; scanf("%d", &score); if (XXX) { printf(YYY);} else { printf(ZZZ); } a.score > 90 / "Nice try" / "Great job" b.score < 91 / "Great job" / "Nice try" c.score < 91 / "Nice try" / "Great job" d.(Not possible for given code)

c

Which expressions for YYY and ZZZ correctly output the indicated ranges? Assume int x's value will be 0 or greater. Choices are in the form YYY / ZZZ. if (YYY) { printf("0-29"); } else if (ZZZ) { printf("30-39"); } else { printf("40+"); } a.x < 29 / x >= 29 b.x < 30 / x >= 30 c.x < 30 / x < 40 d.x > 29 / x > 40

c

Which for loop will iterate 100 times? a.for (i = 0; i < 99; i++) b.for (i = 1; i < 99; i++) c.for (i = 0; i < 100; i++) d.for (i = 1; i < 100; i++)

c

Which value of y results in short circuit evaluation, causing z == 99 to not be evaluated? (y > 50) || (z == 99) a.40 b.50 c.60 d.No such value

c

An exam with 10 questions requires all 10 answers to be correct in order to pass. Which expression represents this condition? a. (numCorrect != 10) ? "Pass" : "Fail" b. (numCorrect = 10) ? "Pass" : "Fail" c. (numCorrect >= 9) ? "Pass" : "Fail" d. (numCorrect == 10) ? "Pass" : "Fail"

d

For the given pseudocode, which XXX and YYY will output the smallest non-negative input (stopping when a negative value is input)? Choices are in the form XXX / YYY. min = 0 val = Get next input min = val While val is not negative If XXX YYY val = Get next input Put min to output a.val > 0 / min = val b.min < val / val = min c.val > min / val = min d.val < min / min = val

d

For what values of integer x will Branch 3 execute? If x < 10 : Branch 1 Else If x > 9: Branch 2 Else: Branch 3 a.Value 10 or larger b.Value 10 only c.Values between 9 and 10 d.For no values (never executes)

d

How many x's will be output? i = 1; while (i <= 3) { j = 1;while (j <= i) { printf("x"); ++j; } printf("\n"); ++i; } a. 0 b. 3 c. 4 d. 6

d

If the input is 12, what is the final value for numItems? int x; int numItems = 0; scanf("%d", &x); if (x <= 12) { numItems = 100;} else { numItems = 200;} numItems = numItems + 1; a. 201 b. 100 c. 200 d. 101

d

What is the output for x = 15? switch (x) { case 10: // Output: "First " break; case 20: // Output: "Second " break; default: // Output: "No match " break; } a.First b.Second c.First Second d.No match

d

What is the output? char letter1; char letter2; letter1 = 'p'; while (letter1 <= 'q') { letter2 = 'x'; while (letter2 <= 'y') { printf("%c%c ", letter1, letter2); ++letter2; } ++letter1; } a.px b.px py c.qx qy d.px py qx qy

d

What is the output? for (i = 0; i <= 10; ++i) { if (i == 6) continue; else printf("%d ", i); } a. 0 1 2 3 4 5 b. 0 1 2 3 4 5 6 c. 0 1 2 3 4 5 7 8 9 d. 0 1 2 3 4 5 7 8 9 10

d

What is the output? int columns; int rows; for (rows = 0; rows < 2; ++rows) { for (columns = 0; columns < 3; ++columns) { printf("x"); } printf(" "); } a.x x b.xx xx c.xx xx xx d.xxx xxx

d

What is the output? int i; for (i = 0; i < 4; ++i) { int factorial = i + 1; for (int j = 0; j < 2; ++j) { printf("%d", factorial * j); } } printf("%d\n", factorial); a.01020304 b.010203048 c.10203048 d.Error: factorial is out of scope

d

What is the output? int main() { for (int i = 0; i < 3; ++i) { printf("%d", i); } printf("%d", i); return 0; } a. 12 b. 122 c. 123 d. Error: The variable i is not declared in the right scope

d

What is y's ending value? int x; int y = 0; scanf("%d", &x); if (x = 20) { y = 3; } a. 0 when the input is 20, else 3 b. Always 0 no matter what the input c. 3 when the input is 20, else 0 d. Always 3 no matter what the input

d

Which conditional expression would cause myBoolean to short circuit to true given x = 10 and y = 5? a. myBoolean = (x < 5 || y < 10 ) ? false: true b. myBoolean = (x > 5 && y > 10 ) ? true: false c. myBoolean = (x < 5 || y > 10 ) ? true: false d. myBoolean = (x > 5 || y > 10 ) ? true: false

d

Which expression evaluates to true if the corresponding characters of strings s1 and s2 are equal independent of case? Ex: "C" and "c" should be considered equal. a. strcmp(str1[i], str2[i]) == 0 b. strcmp(tolower(str1[i]),tolower(str1[i])) == 0 c. strcmp(str1[i], toupper(str2[i])) == 0 d. strcmp(toupper(str1[i]), toupper(str2[i])) == 0

d

Which expressions for XXX and YYY correctly output the text for pre-teen and teenager? Choices are in the form XXX / YYY. if (XXX) { // Output "Pre-teen" } else if (YYY) { // Output "Teenager" } a.age >= 13 / age <= 19 b.age <= 13 / age > 13 c.age < 13 / age < 19 d.age < 13 / age <= 19

d

Which input for char c causes "Done" to be output next? c = 'y'; while (c = 'y') { // Do something printf("Enter y to continue, n to quit: \n"); scanf("%c", &c); } printf("Done\n"); a. 'y' only b. 'n' only c. Any value other than 'y' d. No such value (infinite loop)

d

Which input value causes the loop body to execute a 2nd time, thus outputting "In loop" again? string s = "Go"; while ((s != "q") && (s != "Q")){ printf("In loop\n"); scanf("%s", s); } a. "q" only b. "Q" only c. Either "q" or "Q" d. "Quit"

d

Why is it best to develop a large program incrementally? a. The code is less modular b. The compiler will compile without errors c. The program is easier to write but harder to debug d. The program is easier to debug

d


Kaugnay na mga set ng pag-aaral

Personal Finance Chapter 2 Study Guide

View Set

Chapter 6.7 - Dividing Polynomials

View Set

Prep U - Honan - Neurologic Trauma

View Set

Describing chemical reactions 8.1 chem

View Set