COP1220 Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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

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

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

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

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

What does the following code do after populating urlArr? char urlArr[9]; int length = strlen(urlArr); // urlArr is populated here for (int i = 0; i < length; ++i){ printf("%s\n", urlArr[8]); } a.Prints the 8th character of every string in urlArr b.Prints the 8th character in urlArr c.Prints the last string in urlArr 9 times d.Prints every string in urlArr

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

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

B

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 corrects the logic error in the following program? void FindPrevNext (int x, int prev, int next) { prev = x - 1; next = x + 1; } int main(void) { int x = 10; int y; int z; FindPrevNext (x, y, z); printf("Previous = %d, Next = %d", y, z); return 0; } a.The variables prev and next should be passed by reference b.The variables y and z should be initialized to 0 c.The function FindPrevNext() should have a return statement for variables prev and next d.prev and next should be initialized in FindPrevNext()

A

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

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

What is output? printf("Calculation: %+09.4lf \n", -13.785742835); a.Calculation: -13.7857 b.Calculation: 1.3780e+01 c.Calculation: +13.7857 d.Calculation: -013.7857

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

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

C

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

What is the output?void WaterTemperatureForCoffee(int temp) { if (temp < 195) { printf("Too cold."); } else if ((temp >= 195) && (temp <= 205)) { printf("Perfect temperature."); } else if (temp > 205) { printf("Too hot."); } } int main(void) { WaterTemperatureForCoffee(205); WaterTemperatureForCoffee(190); return 0; } a.Too cold. b.Perfect temperature. c.Perfect temperature.Too cold. d.Perfect temperature.Too cold.

D

Which statement correctly assigns 12 into the fifth row and third column of array itemArray? a.numVals[5][3] = 12; b.numVals[3][5] = 12; c.numVals[4][2] = 12; d.numVals[2][4] = 12;

C

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

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

Which is true regarding how functions work? a.After a function returns, its local variables keep their values, which serve as their initial values the next time the function is called b.A function's local variables are discarded upon a function's return; each new call creates new local variables in memory c.A return address indicates the value returned by the function d.If a function returns a variable, the function stores the variable's value until the function is called again

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

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

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

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

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 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 if the value of modString is "Great. They won. " void MyFct(char modString[]) { int i; // Loop index for (i = 0; i < strlen(modString); ++i) { if (modString[i] == ' ') { modString[i] = '-'; } } } a.Great-They-won- b.Great.-They won. c.Great.-They-won.- d.Great.-They-won.

C

What is output? char level[] = "Minimum"; int amount = 13; printf("You have a %-.3s. of %d miles left to go \n", level, amount); return 0; a."You have a Minimum. of 13 miles left to go"b."You have a Min of 13 miles left to go"c."You have a Min. of 13 miles left to go"d.Error: The string sub-specifier is not correct

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 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 XXX outputs each element of array customerName to a file called CustomerList.txt using a file pointer? char* customerName[5] = {"Bob", "Sally", "Jim", "Joe", "Denise"}; FILE *inputFile = NULL; int numberPlayers;inputFile = fopen ("CustomerList.txt", "w"); for (int i = 0; i < (5); ++i) { XXX } a.fprintf("CustomerList.txt", "%s\n", customerName[i]); b.fprintf(inputFile, "%s\n", customerName); c.fprintf (inputFile, "%s\n", customerName[i]); d.fprintf(stdout, "%s\n", customerName[i]);

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 is not true? a.A char* can be passed as const* argument. b.Strings passed as char* arguments can be modified by the function. c.Strings passed as const char* can be modified by the function. d.Each string library function operates on one or more strings.

C

What is the output? double CheckForFever (double temperature) { const double NORMAL_TEMP = 98.6; const double CUTOFF_TEMP = 95; double degreesOfFever; if (temperature > NORMAL_TEMP) { degreesOfFever = temperature - NORMAL_TEMP; printf("You have %lf degrees of fever.", degreesOfFever); } else if (temperature < CUTOFF_TEMP) { degreesOfFever = CUTOFF_TEMP - temperature; printf("Your temperature is %lf below 95.", degreesOfFever); } return degreesOfFever; } int main(void) { double bodyTemperature; double degreesOfFever; bodyTemperature = 96.0; printf("Checking for fever..."); degreesOfFever = CheckForFever(bodyTemperature); return 0; } a.(Nothing is output) b.Checking for fever...Your temperature is 2.6 below 95. c.Checking for fever...Your temperature is 2.6 below 95. d.Checking for fever...

D

Which is true for the following code? char userText[10]; userText[0] = 'B'; userText[1] = 'o'; userText[2] = 'o'; userText[3] = 'k'; userText[4] = '\0'; ...userText[3] = 't'; a.The first four characters of the array userText are Book. b.The first five characters of the array userText are Bookt. c.The compiler generates an error because element 3 can't be overwritten. d.Printing the array userText will work fine because the new string is 4 characters and the array size is 10.

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

How many elements are in the array? int userVals[2][4]; a.2 b.4 c.6 d.8

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 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 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 declares two related integer arrays named personName and personAge each with 50 elements? a.int personName, personAge; b.int personName, personAge = 50; c.int personName = 50;int personAge = 50; d.int personName[50];int personAge[50];

D

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 error in this code? void MyFct(int& x) { x = (x * x) + 1; } int main(void) { printf("%d", MyFct(9)); return 0; } a.MyFct() cannot be called with a literal b.MyFct() is missing a return statement c.MyFct() cannot both read and assign x d.No error exists; the program will output 82

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

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

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

A function defined beginning with void SetNegativesToZeros(int userValues[], ... should modify userValues such that any negative integers are replaced by zeros. The function _____. a.should make a local copy of the array and then set the copy's negative values to zeros b.cannot be written because an array passed to a function is constant so cannot be modified c.can modify the array's elements directly because arrays are passed by pointer d.should define userValues as const int& userValues to be able to modify the array's elements

C

Given integers i, j , k, which XXX correctly passes three integer arguments for the following function call? addInts XXX; a.(j, 6 + 7) b.(i + j + k) c.(10, j, k +5) d.(10 15 20)

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 XXX calculates the area using the CalcSquare() function? The formula to calculate the area of a circle is pi * r 2 . double CalcSquare(double x) { return x*x; } double CalcArea(double r) { const double PI_VAL = 3.14159265;XXX; } int main(void) { printf("%lf", CalcArea(5.0)); return 0; } a.PI_VAL * r * r; b.PI_VAL * CalcSquare(r); c.return PI_VAL * CalcSquare(r); d.return PI_VAL * CalcSquare(r) * CalcSquare(r);

C

Which XXX will result in output "4.00 feet is equal to 1.22 meters"? #include <stdio.h> void ConvertFeetToMeters(float numFeet, float* numMeters) { *numMeters = numFeet / 3.28084; } int main(void) { float numFeet = 4.0; float numMeters = 0.0; XXX printf("%.2f feet is equal to %.2f meters", numFeet, numMeters); return 0; } a.ConvertFeetToMeters(*numFeet, &numMeters);b.ConvertFeetToMeters(numFeet, *numMeters);c.ConvertFeetToMeters(numFeet, &numMeters);d.ConvertFeetToMeters(&numFeet, *numMeters);

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

Given an integer array of size NUM_ELEMENTS, which XXX, YYY, and ZZZ will count the number of times the value 4 is in the array? Choices are in the form XXX / YYY / ZZZ.int myArr[NUM_ELEMENTS]; int cntFours; XXX for (i = 0; YYY; ++i) { if (myVals[i] == 4) {ZZZ; } } a.cntFours = myArr[0]; / i > NUM_ELEMENTS; / cntFours = myArr[i]; b.cntFours = myArr[1]; / i < NUM_ELEMENTS; / cntFours = myArr[i] + 1; c.cntFours = 1; / i > NUM_ELEMENTS; / cntFours = cntFours + 1; d.cntFours = 0; / i < NUM_ELEMENTS; / ++cntFours;

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

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

The following program generates an error. Why? void PrintSum(int num1, int num2) { printf("%d", num1 + num2); } int main(void) { int y;y = PrintSum(4, 5); return 0; } a.The void function is missing a "return;" statement b.The values 4 and 5 cannot be passed directly to PrintSum() c.main() has a return statement that returns the value 0 d.PrintSum() has void return type, so cannot be assigned to a variable

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

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

How many function calls exist in the following code? int Calc1 (int a, int b) { return a + b / 2; } int Calc2 (int a, int b) { return a * b / 100; } int main(void) { int x; int y; x = Calc1 (5,3); printf("%d", x); y = Calc2 (5,3); printf("%d", &y); printf("%d", Calc2 (5,3)); return 0; } a.2 b.3 c.4 d.5

B

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

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

The fopen(str) function has a string parameter str that specifies the _____ of the file to open. a.name b.size c.contents d.reference

A

What is output? int pop = 1340; printf("There are %06d residents of the city. \n", pop); a.There are 001340 residents of the city. b.There are 1340 residents of the city. c.There are 0001340 residents of the city. d.There are +0001340 residents of the city.

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

Given integer variables totalTickets, vipTickets, and sessionNum, which line of code correctly calls the following function? void FinalTally(int* totalAttendees, int* vipAttendees, int numSessions); a.FinalTally(totalTickets, vipTickets, &sessionNum); b.FinalTally(&totalTickets, &vipTickets, sessionNum); c.FinalTally(*totalTickets, *vipTickets, sessionNum); d.FinalTally(&totalTickets, &vipTickets, &sessionNum);

B

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

What is the purpose of the & symbol in the following code? int* myVar; int distance = 132; myVar = &distance; a.Refers to the function parameter distance b.Refers to the constant distance c.Refers to the integer value of distance d.Refers to the memory address of distance

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


Set pelajaran terkait

CDE 232 - Human Development Chapter 13

View Set

Operating, Investing, or Financing?

View Set

Random Variables and Discrete Probability Distribution

View Set

French Multiple Choice Possibilities

View Set

Algebra 1 Unit 5 Linear Functions

View Set