COP1220 Quiz 2, COP1220, COP1220 Final

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

An identifier can _____ . a.be a reserved word b.start with an underscore c.contain a period d.contain spaces

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

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

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 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 XXX is valid for the following code? int CalcSum(int a, int b) { return a + b; } int main() { int y; XXX return 0; } a.y = CalcSum(); b.y = CalcSum(4, 5); c.y = CalcSum(4 + 5); d.CalcSum(y, 4, 5);

B

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

Which function has two int parameters, startVal and endVal, that are passed by pointer? a.void function SwapVals(int startVal, int endVal) b.void function SwapVals(int* startVal, int* endVal) c.void function SwapVals(int &startVal, int &endVal) d.void function SwapVals(*startVal, *endVal)

B

Which is true regarding passing C strings to functions? a.A C string cannot be passed to a function b.A C string is automatically passed by pointer c.Functions that modify a string must have a char return type d.Passing a C string to a function creates a copy of that string within the function

B

Which is true regarding this preprocessor directive? #include <stdfile.h> a.The preprocessor looks for stdfile in the same directory as the including file b.The preprocessor looks for stdfile in the system's standard library c.The preprocessor looks for stdfile on the web d.The directive causes an error because of a missing .h at the end of stdfile

B

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

Identify the correct declaration of an array of strings. a.char stringArr[10][50]; b.char stringArr[10]; c.stringArr[10][50]; d.char[50] stringArr[10];

A

Identify the statement that checks whether myChar exists within myString, returning NULL if myChar does not exist, or returning the address of the first occurrence if myChar does exist? a.strchr(myString, myChar) b.strcat(myString, myChar) c.if(myChar != NULL) d.strcmp(myString, myChar)

A

The feof() function of input streams returns a _____. a.false when the end of the file has not been reached b.false when the end of the file has been reached c.true when the end of the file has not been reached d.true when the end of the file has been reached

A

What are the possible values for ((rand() % 9) + -4)? a.-4...4 b.-9...9 c.0...4 d.0...9

A

What is the ending value of y? int x; int y; x = 6; y = (1 / 2) * (x + 5); a.0 b.3 c.5 d.6

A

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

Which XXX / YYY declare an array having MAX_SIZE elements and initializes all elements with -1? const int MAX_SIZE = 4; int myNumbers[XXX]; int i; for (i = 0; i < YYY; ++i) { myNumbers[i] = -1; } a.MAX_SIZE / MAX_SIZE b.MAX_SIZE / MAX_SIZE - 1 c.MAX_SIZE - 1 / MAX_SIZE d.MAX_SIZE - 1 / MAX_SIZE - 1

A

Which XXX and YYY correctly output the smallest values? Array userVals contains 100 elements that are integers (which may be positive or negative). Choices are in the form XXX / YYY. // Determine smallest (min) value int minVal; XXX for (i = 0; i < 100; ++i) { if (YYY) { minVal = userVals[i]; } } printf("Min: %d" ,minVal); a.minVal = userVals[0]; / userVals[i] < minValb.minVal = 0; / userVal > minValc.minVal = 0; / userVal < minVald.minVal = userVals[0]; / userVals[i] > minVal

A

Which XXX is used to read and store the data into the variable numberPlayers from the file that is opened by the stream inputFile? int main(void) { FILE* inputFile = NULL; int numberPlayers; inputFile = fopen("playerNumber.txt", "r"); if (inputFile==NULL) { printf("Could not open file numFile.txt."); return 1; } else { XXX; printf("Players Number: " , numberPlayers); } return 0; } a.fscanf(inputFile, "%d", &numberPlayers); b.scanf(inputFile, "%d", &numberPlayers); c.sscanf(inputFile, "%d", &numberPlayers); d.scanf("%d", &numberPlayers);

A

Which function call passes a string myStr to the given function? void StrMod(char modString[]) { int i; // Loop index for (i = 0; i < strlen(modString); ++i) { if (modString[i] == '.') { modString[i] = '!'; } } } a.StrMod(myStr); b.StrMod(myStr[]); c.StrMod(char myStr[]); d.StrMod(char myStr[strlen(myStr)]);

A

For the given program, how many printf statements will execute? void PrintShippingCharge(double itemWeight) { if ((itemWeight > 0.0) && (itemWeight <= 10.0)) { printf("%lf\n", itemWeight * 0.75); } else if ((itemWeight > 10.0) && (itemWeight <= 15.0)) { printf("%lf\n", itemWeight * 0.85); } else if ((itemWeight > 15.0) && (itemWeight <= 20.0)) {printf("%lf\n", itemWeight * 0.95); } } int main(void { PrintShippingCharge(18); PrintShippingCharge(6); PrintShippingCharge(25); return 0; } a.1 b.2 c.3 d.9

B

Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling? a.All the errors b.The first error only c.The middle error only d.The last error only

B

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

Given that integer array x has elements 4, 7, 3, 0, 8, what are the elements after the loop? int i; for (i = 0; i < 4; ++i) { x[i] = x[i + 1]; } a.4, 4, 7, 3, 0 b.7, 3, 0, 8, 8 c.7, 3, 0, 8, 4 d.Error: Invalid access

B

The following program results in a compiler error. Why? int FindMin(int a, int b) { int min; if (a < b) { min = a; } else { min = b; } return min; } int main(void) { int x;int y; scanf("%d", &x); scanf("%d", &y); min = FindMin(x,y); printf("The smaller number is: %d\n", min); return 0; } a.FindMin() should be defined after main(), not before. b.The variable min is declared in FindMin(), but is used in main() c.The variable min is not initialized d.The variable min should be a parameter

B

The numNegatives variable counts the number of negative values in the array userVals. What should numNegatives be initialized to? int userVals[20]; unsigned int i; numNegatives = XXX; for (i = 0; i < 20; ++i) { if (userValues[i] < 0) { numNegatives = numNegatives + 1; } } a.No initialization needed b.0 c.-1 d.userVals[0]

B

What does the following code do? char inputString[30] = "Ther3 are n0 num33r5 4er3"; int length = strlen(inputString); char numString[30]; int numIndex = 0; char alphaString[30]; int alphaIndex = 0; for (int i = 0; i < length; ++i){ if(isalpha(inputString[i])){ alphaString[alphaIndex]=inputString[i]; alphaIndex +=1; } else{ if(isdigit(inputString[i])){ numString[numIndex]=inputString[i]; numIndex+=1; } } } a.Removes spaces from inputString by moving chars to another char array b.Sorts alphabetic and numeric chars in inputString into two separate arrays c.Removes all numeric characters from inputString d.Sorts chars in inputString in alphabetical order

B

What is output? double MyFct(double a, double b) { return (a + b) / 2.0; } int main(void) { double x = 3.0; double y = 5.0; double z = 8.0; double t; t = MyFct(x, y); t = MyFct(t, z); printf("%lf\n", t); return 0; } a.4.0 b.6.0 c.8.0 d.16.0

B

What is the ending value of myStr? char myStr[5] = "Hi"; strcpy(myStr, "Hey"); a.Hi b.Hey c.HiHey d.HeyHi

B

What is the ending value of w? int w; int y; y = 34; w = y % 5; a.1 b.4 c.6 d.7

B

What is the ending value of z? int x = 5; int y = 12; double z; z = (double)(y / x); a.0.0 b.2.0 c.2.4 d.3.0

B

What is the output? #include <stdio.h> int main(void) { double dividend = 0.0; double divisor = 0.0; printf("%lf\n", dividend / divisor); dividend = 3.0; printf("%lf\n", dividend / divisor); return 0; } a.inf nan b.nan inf c.inf 0.0 d.nan 0.0

B

Which XXX would generate "the USA has 50 states" as the output for "the usa has 50 states" as the input? #include <stdio.h> #include <string.h> int main(void) { char userInput[100]; char* stringPosition = NULL; printf("Enter a line of text: "); fgets(userInput, 100, stdin); stringPosition = strstr(userInput, "usa"); if (stringPosition != NULL) { XXX } printf("%s\n", userInput); return 0; } a.strncpy(*stringPosition, "USA", 3); b.strncpy(stringPosition, "USA", 3); c.strncpy(stringPosition, "USA"); d.strncpy(stringPosition, 'USA', 3);

B

Which assigns the array's last element with 99?int myVector[15]; a.myVector[0] = 99; b.myVector[14] = 99; c.myVector[15] = 99; d.myVector[16] = 99;

B

Which best describes what is output? Assume v is a large array of ints. int i; int s; s = v[0]; for (i = 0; i < N_SIZE; ++i) { if (s > v[i]) { s = v[i]; } } printf("%d \n", s); a.first value in v b.min value in v c.last value in v d.max value in v

B

Which character array declaration is appropriate? a.char name[5] = "Alexa"; b.char name[5] = "Alex"; c.char name[5] = "Alexandria"; d.char name[5] = "Alexander";

B

Which expression doubles x? a.x += 2; b.x *= 2; c.x *= x; d.x *= x * 2;

B

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

Which prints a percent sign? a.printf("\%"); b.printf("%%"); c.printf("%"); d.printf('%');

B

A program should compute two times x. Which statement has a logic error? a. y = x + x; b. y = 2 * x; c. y = x * x; d. y = x * 2;

C

For the following function, which is a valid function call? Assume maxValue is an integer. int Max(int x, int y) { if (x > y){ return x; } else { return y; } } a.maxValue = Max(15 25); b.maxValue = Max(); c.maxValue = Max(15, Max(35, 25)); d.Max = maxValue(15, 25);

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

Given a function defined beginning with: void PrintMaxItem(int valsArray[], ... that prints the largest item in any array of integers. How would this function most likely iterate through the array? a.for (i = 0; i < valsArray.size(); ++i) where size is a built-in function for arrays b.for (i = 0; i < valsArray; ++i) due to the compiler knowing the size of arrays c.for (i = 0; i < arraySize; ++i) where arraySize is a second function parameter d.for (i = 0; i != lastItem; ++i) where lastItem is the value of the array's last element

C

Given char x and char z, which assigns x with the character value held in z? a.x = 'z'; b.x = "z"; c.x = z; d.'x' = 'z';

C

Given two arrays, studentNames that maintains a list of students, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX / YYY. char studentNames[NUM_STUDENTS]; int studentScores[NUM_STUDENTS]; int i; for (i = 0; i < NUM_STUDENTS; ++i) { if (XXX > 80) { printf("%s \n", YYY ); } } a.studentNames[i] / studentNames[i] b.studentNames[i] / studentScores[i] c.studentScores[i] / studentNames[i] d.studentScores[i] / studentScores[i]

C

Two arrays, itemsNames and itemsPrices, are used to store a list of item names and their corresponding prices. Which is true? a.Using two arrays saves memory versus using one array. b.Both arrays should be of the same data type. c.Both arrays should be declared to have the same number of elements. d.The item names should appear in both arrays.

C

What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) { if (pointVar1 == NULL && pointVar2 == NULL) { printf("Pointer is null\n");} else if (*pointVar2 > *pointVar1) { printf("%p\n", *pointVar2);} else if (*pointVar1 > *pointVar2) { printf("%p\n", *pointVar1); } } int main() { int num1 = 5; int num2 = 9; CheckValue(&num1, &num2); return 0; } a.0 b.5 c.9 d.Pointer is null

C

What is the ending value of cost? int numApples = 3; double cost; cost = 1.2 * numApples; a. 3 b. 3.2 c. 3.6 d. 4

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

What is the output? int Calc(int num1, int num2) { return 1 + num1 + num2; } int main(void) { int x;x = Calc(4, 5); printf("%d", Calc(x, 5)); return 0; } a.5 b.10 c.16 d.Error: Cannot have a function call in a printf statement

C

Which XXX and YYY will find the minimum value of all the elements in the array? Choices are in the form XXX / YYY. int userVals[NUM_ROWS][NUM_COLS]; int minVal = userVals[0][0]; for (i = 0; i < NUM_ROWS; ++i) { for (j = 0; j < NUM_COLS; ++j) { if (XXX) { YYY; } } } a.userVals[i] < minVal / minVal = userVals[i] b.userVals[j] < minVal / minVal = userVals[j] c.userVals[i][j] < minVal / minVal = userVals[i][j] d.userVals[i][j] > minVal / minVal = userVals[i][j]

C

Which assigns the array's first element with 99?int myVector[4]; a.myVector[] = 99; b.myVector[-1] = 99; c.myVector[0] = 99; d.myVector[1] = 99;

C

Which data type can be used instead of int to avoid overflow for an integer containing the value 3,000,000,000,000? a.double b.long c.long long d.long int

C

Which expression is most appropriate for randomly choosing a day of the week? a.rand() % 1; b.rand() % 6; c.rand() % 7; d.rand() % 8;

C

Which header file is required to access the file pointer (FILE*)? a.stdlib.h b.stddef.h c.stdio.h d.stdint.h

C

Which includes a header file in the same directory as the file including the header? a.#include "myheader.h"; b.#include 'myheader.h'; c.#include "myheader.h" d.#include 'filename.h'

C

Which is a valid preprocessor directive? a.#include filename.h b.#include filename.h; c.#include "filename.h" d.#include "filename.h";

C

Which is an invalid access for the array? int numsList[5]; int x = 3; a.numsList[x-3] b.numsList[0] c.numsList[x+2] d.numsList[(2*x) - x]

C

Which is correct? a.int area = 3.2; b.500 = int distance; c.int changeAmt = -321; d.212 = length;

C

Which is not a valid identifier? a.firstName b.first_name c.1stName d.name1

C

Which is the first thing the compiler does when a function is called? a.Converts the function's code to assembly b.Creates instructions to jump to the function c.Stores the address of the function call d.Creates a jump instruction to the function

C

Which assignments would yield a non-floating-point number for y? y = 32.0 + (x / (z + 1.0)); a.x = 0.0; z = 1.0; b.x = -32.0; z = 1.0; c.x = 0.0; z = 0.0; d.x = 1.0; z = -1.0;

D

Which is true about arrays and functions? a.Arrays cannot be passed to functions b.Passing an array to a function creates a copy of that array within the function c.An array is automatically passed to a function as a pointer d.A programmer must first make a copy of an array to pass the array to a function

C

Which statement correctly declares a char array named myText initialized to Hello? a.char myText = {"Hello"}; b.char[10] myText= "Hello"; c.char myText[10] = "Hello"; d.myText[] = {"Hello"};

C

Which statement declares a two-dimensional integer array called myArray with 3 rows and 4 columns? a.int myArray[3, 4]; b.int myArray[7]; c.int myArray[3][4]; d.int myArray[4][3];

C

Given two integer arrays, largerArray with 4 elements, and smallerArray with 3 elements. What is the result after this code executes? for (i = 0; i < 4; ++i) { largerArray[i] = smallerArray[i]; } a.All the elements of largerArray will get copied to smallerArray. b.Some of the elements of largerArray will get copied to smallerArray. c.All of the elements of smallerArray will get copied to largerArray. d.Error: The two arrays are not the same size.

D

How many elements does the array declaration create? int scores[10]; // Array declaration scores[0] = 25; scores[1] = 22; scores[2] = 18; scores[3] = 28; a.0 b.4 c.9 d.10

D

The following program generates an error. Why? const int NUM_ELEMENTS = 5; int userVals[NUM_ELEMENTS]; unsigned int i; userVals[0] = 1; userVals[1] = 7; userVals[2] = 4; for (i = 0; i <= NUM_ELEMENTS; ++i) { cout << userVals[i] << endl; } a.Variable i is declared as an unsigned integer. b.The array userVals has 5 elements, but only 3 have values assigned. c.The integer NUM_ELEMENTS is declared as a constant. d.The for loop tries to access an index that is out of the array's valid range.

D

What are the ending contents of the array? Choices show elements in index order 0, 1, 2. int yearsList[3]; yearsList[0] = 5; yearsList[1] = yearsList[0]; yearsList[0] = 10; yearsList[2] = yearsList[1]; a.5, 5, 5 b.5, 10, 10 c.10, 10, 10 d.10, 5, 5

D

What is output? #include <stdio.h> int main() { float newSize = 1.0; int i; for (i = 100; i < 120; ++i) { newSize *= i; } printf("%f", newSize); return 0; } a.1.000000 b.120.000000 c.4253829132348564723899756263864532992.000000 d.infinity

D

What line of code makes the character pointer studentPointer point to the character variable userStudent? char userStudent = 'S'; char* studentPointer; a.userStudent = *studentPointer ;b.userStudent = studentPointer; c.*studentPointer = &userStudent; d.studentPointer = &userStudent;

D

What will a compiler do for the following code? /* numItems = 2; /* Total items to buy */rate = 0.5; */ a.Ignore numItems = 2, but generate code for rate = 0.5. b.Generate code for numItems = 2, but ignore rate = 0.5. c.Ignore both statements. d.Generate an error.

D

What will a compiler do for the following three lines of code?// x = 2; // width// y = 0.5// z = x * y; Total area a.Yield an error for line 1 (x = ...) b.Yield an error for line 2 (y = ...) c.Yield an error for line 3 (z = ...) d.Ignore all three lines

D

Which XXX converts the string userStr to uppercase? for (i = 0; userStr[i] != '\0'; ++i) { XXX; } a.userStr = isupper(userStr);b.userStr = toupper(userStr);c.userStr[i] = isupper(userStr[i]);d.userStr[i] = toupper(userStr[i]);

D

Which XXX is most appropriate for printing out the char array userText? userText[10] = "zyBook"; for (i = 0; XXX; ++i) { // Print userText[i] } a.i < 6 b.i <= 6 c.userText != '\0' d.userText[i] != '\0'

D

Which XXX prints the message only if str1 and str2 are equal? if (XXX) { // Print "strings are equal" } a.str1 == str2 b.strcat(str1, str2) == 0 c.strcpy(str1, str2) == 0 d.strcmp(str1, str2) == 0

D

Which best describes the meaning of a 1 (true) being output? Assume v is a large array of ints. int i; bool s; for (i = 0; i < N_SIZE; ++i) { if (v[i] < 0) { s = true; } else { s = false; } } printf("%d", s); a.first value is negative b.all values are negative c.some value other than the last is negative d.last value is negative

D

Which declaration assigns a variable with 5 such that the value can not be later changed? a. const int = 5; b. int numItems = 5; c. int NUM_ITEMS = 5; d. const int NUM_ITEMS = 5;

D

Which evaluates to true for the string str = "beta123"? a.isalpha(str[4]) b.isdigit(str[0]) c.isspace(str[2]) d.islower(str[1])

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

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

c

A double variable stores a value in 64 bits, using some bits for mantissa, some for exponent, and one for sign. Which is true about a double variable? a. Limited bits may cause some rounding of the mantissa. b. If a value is too large for a double, a float should be used instead. c. If a value is too large for a double, a long should be used instead. d. The compiler may sometimes use 63 bits for the mantissa.

A

Given an array customerNames that stores 10 strings, each with a maximum of 50 characters. Identify the statement that will correctly output the fifth string in customerNames. char customerNames[10][50]; strcpy(customerNames[0], "Bob"); strcpy(customerNames[1], "Jim"); strcpy(customerNames[2], "Sally"); strcpy(customerNames[3], "Juan"); strcpy(customerNames[4], "Bella"); strcpy(customerNames[5], "Sam"); a.printf("%s \n", customerNames[4]); b.printf("%s \n", customerNames[5]); c.printf("%s \n", customerNames); d.printf("%s \n", customerNames[4][4]);

A

Given function Multiply(u, v) that returns u * v, and Add(u, v) that returns u + v, which expression corresponds to: Add(Multiply(x, Add(y, z)), w) a.(x * (y + z)) + w b.(x + (y + z) * w) c.((x * y) + z) + w d.(x * (y + z) * w)

A

Given two arrays, which code will output all the arrays' elements, in the order key, item followed by a newline?int keysList[SIZE_LIST];int itemsList[SIZE_LIST]; a.for (i = 0; i < SIZE_LIST; ++i) { printf("%d, %d \n", keysList[i], itemsList[i]); } b.printf("%d, %d \n", keysList[SIZE_LIST - 1], itemsList[SIZE_LIST - 1]); c.printf("%d, %d \n", keysList[SIZE_LIST], itemsList[SIZE_LIST]); d.for (i = 0; i < SIZE_LIST - 1; ++i) { printf("%d, %d \n", keysList[i], itemsList[i]); }

A

How many function parameters exist in the code? double FahrenheitToCelsius(double fahrenheit) { return (fahrenheit - 32.0) * 5.0 / 9.0; } int main(void) { double fahrenheit; scanf("%lf", &fahrenheit); int c1; int c2; int c3; int c4; c1 = FahrenheitToCelsius(fahrenheit); c2 = FahrenheitToCelsius(32); c3 = FahrenheitToCelsius(78); c4 = FahrenheitToCelsius(100); return 0; } a.1 b.3 c.4 d.Error: Cannot pass a variable to a function

A

What is the output if myContact.txt file does not exist? int main(void) { FILE* inputFile = NULL; printf("Opening the file."); inputFile =fopen("myContact.txt", "r"); if (inputFile ==NULL) { printf("Could not open the file. "); return 1; } fclose(inFS); return 0; } a.Opening the file. Could not open the file. b.Could not open the file. c.Opening the file. d.Could not open the file. Opening the file.

A

What is the output? const int MAX_LEN = 10; char userStr[MAX_LEN] = "PASS123"; int i; for (i = 0; userStr[i] != '\0'; ++i) { userStr[i] = tolower(userStr[i]); } a.pass123 b.Pass123 c.PASS123 d.Error: The string contains a digit that cannot be converted to lowercase

A

What is the output? void Swap(int& x, int y) { int tmp; tmp = x; x = y;y = tmp; } int main(void) { int p = 4, q = 3; Swap(p, q); printf("p = %d, q = %d\n", p, q); return 0; } a.p = 3, q = 3 b.p = 4, q = 3 c.p = 3, q = 4 d.Error: Argument names must match parameter names

A

Assuming char* firstSymbol; is already declared, return a pointer to the first instance of an '!' in userInput. a.firstSymbol = strchr(*userInput,'!'); b.firstSymbol = strchr(userInput, '!'); c.firstSymbol = strchr('!', userInput); d.firstSymbol = strrchr('!', userInput);

B

What is the output? int MyFct(int x) { int y; x = x * 2; y = x + 1; return y; } int main(void) { int a; a = 5; printf("%d %d", a, MyFct(a)); return 0; } a.5 6 b.5 11 c.6 11 d.Error: Cannot assign parameter x

B

What line of code assigns a char variable outputGames with the value the gamesPointer points to? char userGames = 'B'; char* gamesPointer; a.outputGames = gamesPointer; b.outputGames = *gamesPointer; c.someChar = &gamesPointer; d.gamesPointer = outputGames;

B

Which XXX causes the program to output the message "Hello!"? void PrintMessage() { printf("Hello!"); } int main(void) { XXX; return 0; } a.printf("%s", PrintMessage())b.PrintMessage()c.void PrintMessage()d.PrintMessage("Hello!")

B

Which statement is incrementing the integer x, where y is also an integer? a.x = x - 1; b.x = x + 1; c.y = x + 1; d.y = x - 1;

B

Which statement outputs "Success!" to the system's standard output file using a file pointer? a.fprintf("%s \n", "Success!") b.fprintf(stdout, "Success!"); c.printf("%s \n","Success!") d.printf("Success!")

B

Given two integer arrays origList = {2, 3, 4, 5} and offsetList = {6, 7, 8, 9}, which statement prints out the sum of the second element in the origList with the corresponding element in the offsetList? a.printf("%d \n", origList + offsetList); b.printf("%d \n", origList[2] + offsetList[2] ); c.printf("%d \n", origList[1] + offsetList[1]); d.printf("%d \n", origList[1] + offsetList[2]);

C

How many function arguments exist in the code? double FahrenheitToCelsius(double fahrenheit){ return (fahrenheit - 32.0) * 5.0 / 9.0; } int main(void) { double fahrenheit; scanf("%lf", &fahrenheit); int c1; int c2; int c3; c1 = FahrenheitToCelsius(fahrenheit); c2 = FahrenheitToCelsius(32); c3 = FahrenheitToCelsius(fahrenheit + 5.0); return 0; } a.1 b.2 c.3 d.4

C

A pointer is a(n) _____ that contains a _____. a.constant, memory address b.array, constant value c.struct, constant value d.variable, memory address

D

For the given program, which XXX iterates through the array to find the state that is input (userState) until a match is found? string stateNames[NUM_STATES]; int statePop[NUM_STATES]; string userState; bool foundState = false; unsigned int i; scanf("%s",userState); foundState = false; for (i = 0; XXX; ++i) { if (stateNames[i] == userState) { foundState = true; printf("%s, %d \n", userState, statePop[i]); } } a.(i < NUM_STATES - 1) b.(i < NUM_STATES) c.(i < NUM_STATES - 1) && (!foundState) d.(i < NUM_STATES) && (!foundState)

D

Given that integer array x has elements 5, 10, 15, 20, what is the output? int i; for (i = 0; i < 4; ++i) { printf("%d ", x[i] + x[i + 1]); } a.10, 15, 20, 5 b.15, 25, 35, 20 c.15, 25, 35, 25 d.Error: Invalid access

D

Given two integer arrays prevValues and newValues. Which code copies the array prevValues into newValues? The size of both arrays is NUM_ELEMENTS. a.newValues = prevValues; b.newValues[] = prevValues[]; c.newValues[NUM_ELEMENTS] = prevValues[NUM_ELEMENTS]; d.for (i = 0; i < NUM_ELEMENTS; ++i) { newVals[i] = prevVals[i]; }

D

What is output? #include <stdio.h> int main() { int myInt; int* myRestaurant; int myVar; int* myBill = NULL; myInt = 10; myRestaurant = &myInt; myVar = *myBill; myVar = *myRestaurant + 10.5; printf("%f\n", myVar); return 0; } a.10.5 b.20.5 c.Error: Syntax error d.Runtime errors

D

Which assigns the last array element with 20.int userNum[N_SIZE]; a.userNum[20]; b.userNum[] = 20; c.userNum[N_SIZE] = 20; d.userNum[N_SIZE - 1] = 20;

D

Which is a valid definition for a function that passes two integers (a, b) as arguments, and returns an integer? a.MyFunction(int a, int b) b.int MyFunction(a, b) c.void MyFunction (a, b) d.int MyFunction(int a, int b)

D

Which is correct? a.int main(void) { pkgHeight;pkgLength; pkgWidth; pkgVol = pkgHeight * pkgLength * pkgWidth; } b.int main(void) { int pkgHeight = 2; int pkgLength = 3; int pkgWidth = 5; pkgVol = pkgHeight * pkgLength * pkgWidth; } c.int main(void) { pkgHeight = 2; pkgLength = 3; pkgWidth = 5; pkgVol = pkgHeight * pkgLength * pkgWidth; } d.int main(void) { int pkgHeight; int pkgLength; int pkgWidth; int pkgVol;pkgVol = pkgHeight * pkgLength * pkgWidth;}

D

Which is true? a.scanf() always truncates the input to avoid the string buffer from overflowing b.Character type variables do not require an ampersand (&) in scanf() c.A format specifier such as "%d" in scanf() is good practice but optional d.Format specifiers for scanf() and printf() are identical

D

Which statement appends an exclamation point at the end of myStr? char myStr[10] = "Yay"; a.strncpy(myStr, "!", 2); b.strcpy(myStr, "!"); c.strcat(myStr, '!'); d.strcat(myStr, "!");

D

Which statement defines the character search function strrchr()? a.Returns the position of the last occurrence of the character. b.Returns the position to the first occurrence of the character. c.Returns a pointer to the first occurrence of the character. d.Returns a pointer to the last occurrence of the character.

D

Which statement, executed once at the start of main(), enables a program to generate a different sequence of pseudo-random numbers from rand() each time the program is run? a.srand(); b.srand(100); c.time(srand()); d.srand((int)time(0));

D

Given char x, which reads an input character into x? a. scanf("%c", &x); b. scanf("%s", x); c. scanf("%s", &x); d. scanf("%c", x);

A

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

myChar is a character variable and is the only declared variable. Which assignment is valid? a.myChar = 't'; b.myChar = "t"; c.myChar = t; d.myChar = 'tx';

A

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

myString is declared as a string and is the only variable declared. Which is a valid assignment? a.myString[] = 'Hello'; b.myString = ["Hey"]; c.myString[] = "H"; d.myString = [Hoy];

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

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

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

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 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 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 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

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 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 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

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 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

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

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

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

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


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

Insurance Pre-licensing : Chapter 2 quiz

View Set