Chapter 7

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

If you declare and initialize an integer array of size 10, but only list 5 values, what values are stored in the remaining 5 indexed variables? a. garbage b. 0.0 c. 0 d. '0'

0

What is the output of the following code fragment? int array[4][4], index1, index2; for(index1 = 0;index1 < 4;index1 ++) for(index2 = 0;index2 < 4;index2 ++) array[index1][index2]=index1 + index2; for(index1 = 0;index1 < 4;index1 ++) { for(index2 = 0;index2 < 4;index2 ++) cout << array[index1][index2] << " "; cout << endl; } a. 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 b. 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 c. 0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9 d. 0 0 0 0 1 1 1 1 1 2 2 2 2 3 3 3 3

0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6

What are the valid indexes for the array shown below? int myArray[25]; a. 1-24 b. 0-25 c. 1-25 d. 0-24

0-24

How many indexed variables does the following array have int myArray[12] = {1,2,3,6,5,4,7,1,2};

12

The following function definition has an error in it. What line is this error on? 0. void f1(const double array[ ], int size) 1. { 2. int i = 0; 3. while(i < size) 4. { 5. array[i] += 2; 6. cout << array[i]; 7. i ++; 8. } 9. } a. 6 b. 7 c. 2 d. 5

5

How many indexed variables does the following array have int myArray[] = {1,2,3,6,5,4,7,1,2};

8

A two dimension array can also be thought of as A. arrays of arrays B. table C. a file D. none E. A and B

A and B

Which of the following declare an array of 5 characters, and initializes them to some known values? a. char array[5] = {'a','b','c','d','e'}; b. char array[4] = {'a','b','c','d','e'}; c. char array[5] = {''}; d. char array[ ] = {'a','b','d','e'}; e. A and C

A and C

Given the following function definition, what modifications need to be made to the search function so that it finds all occurrences of target in the array? int search(const int array[ ], int target, int numElements) { int index = 0; bool found = false; while((!found) && (index < numElements)) { if(array[index] == target) found = true; else index ++; } if(found == true) return index; else return -1; } a. Have the function return the whole array. b. Add another parameter to indicate where to start searching. c. This already can find all occurrences of a given target. d. Add another parameter to indicate where to stop searching.

Add another parameter to indicate where to start searching.

What is wrong with the following code fragment? const int SIZE = 5; float scores[SIZE]; for(int i = 0; i <= SIZE;i ++) { cout << "Enter a score\n"; cin >> scores[i]; } a. Array indexes start at 1 not 0. b. Arrays must be integers. c. should be cin >> scores[0]; d. Array indexes must be less than the size of the array.

Array indexes must be less than the size of the array.

Given the following declarations, which of the following is a legal call to this function? int myFunction(int myValue); int myArray[1000]; a. cout << myFunction(myArray); b. cout << myFunction(myArray[0]); c. myArray = myFunction(myArray); d. myArray[1] = myFunction(myArray[0]); e. B and D

B and D

Which of the following function declarations correctly expect an array as the first argument? a. void f1(int& array, int size); b. void f1(int array, int size); c. void f1(int array[100], int size); d. void f1(float array[ ], int size); e. C and D

C AND D

Given an array of integers of size 5, how does the computer know where the 3rd indexed variable is located? a. It adds space for 3 integers to the base address of the array. b. It adds 3 to the base address of the array. c. It remembers where all the indexed variables of the array are located. d. none of the above

It adds space for 3 integers to the base address of the array.

Given the following function definition, will repeated calls to the search function for the same target find all occurrences of that target in the array? int search(const int array[ ], int target, int numElements) { int index = 0; bool found = false; while((!found) && (index < numElements)) { if(array[index] == target) found = true; else index ++; } if(found == true) return index; else return -1; } a. no b. impossible to tell without looking at the values of the array c. yes d. It depends on the value of target.

No

Arrays can be passed to functions

True

T/F. The following function will work with any size array void function(int array[],int numElements);

True

T/F. The locations of the various indexed variables in an array can be spread out all over the memory

True

T/F. when the function expects an array it should also expect the site of the array and the number of variables

True

a character array terminated with the null character is most correctly called

a c string

Which of the following array declarations are legal? A) int array[ ] = {0,0,0}; B) int size; cin >> size; int array[size]; c. const int size = 9; int array [size]; D) int array[10]; E) all but B

all but B

Why should you use a named constant for the size of an array? A) helps reduce logic errors B) readability of code C) makes changes to the program easier D) all of the above

all of the above

T/F. Following function guarantees the values in the array aren't changed void function(int array[], in numElements

false

T/F.If you use const you do not include it in the function definition

false

Which of the following correctly declare an array that can hold up to 3 rows of 5 columns of doubles? a. float array[3][5]; b. int array[3],[5]; c. float array[3,5]; d. int array[3][5]

float array[3][5];

Which of the following will correctly assign all the values in one array to the other array? (Assume both arrays are of the same type and have SIZE elements) a.for(i = 0;i < SIZE;i ++) array1[i] = array2[i]; b. array1 = array2; c. for(i = 0;i < SIZE;i ++) array1[ ] = array2[ ]; d. array1[ ] = array2;

for(i = 0;i < SIZE;i ++) array1[i] = array2[i];

Which of the following will read values from the keyboard into the array? (Assume the size of the array is SIZE). a. cin >> array[SIZE]; b. cin >> array[ ]; c. cin >> array; d. for(i = 0;i < SIZE;i ++) cin >> array[i];

for(i = 0;i < SIZE;i ++) cin >> array[i];

If we want a search function to search an array for some value and return either the index where the value was found, or -1 if not found, which of the following prototypes would be appropriate? a. void search(const int array, int target, int numElements); b. void search(const int array, int target); c. int search(const int array[ ], int numElements); d. int search(const int array[ ], int target, int numElements);

int search(const int array[ ], int target, int numElements);

What is wrong with the following code? float scores[10], total; a. Arrays must be integers. b. Cannot declare regular and array variables together. c. The 10 should be replaced with a variable name, whose value is input from the user. d. nothing

nothing

Arrays are always passed to a function using___

pass by array

Given the following function definition for a search function, and the following variable declarations, which of the following are appropriate function invocations? const int SIZE = 1000; int search(const int array[ ], int target, int numElements); int array[SIZE], target, numberOfElements; a. result = search(array, target, SIZE); b. search(array[0], target, numberOfElements); c. result = search(array, target, numberOfElements); d. result = search(array[0], target, numberOfElements);

result = search(array, target, numberOfElements);

Given an array named scores with 25 elements, what is the correct way to access the 25th element? a. scores[24] b. scores[25] c. scores[last] d. scores+25

scores [24]

Which of the following function declarations correctly guarantee that the function will not change any values in the array argument? a. void f1(int array[ ], int size); b. void f1(int array[ ], const int size); c. void f1(int array[ ], int size) const; d. void f1(int &array, int size); c. void f1(const int array[ ], int size);

void f1(const int array[ ], int size);

Which of the following function declarations will accept the following two-dimension array? int pages[10][30]; a. void f1(int pages[ ][ ], int size); b. void f1(int pages[ ][30], int size); c. void f1(int& pages, int size); d. void f1(int pages[10][ ], int size);

void f1(int pages[ ][30], int size);

Which of the following function declarations could be used to input data from the keyboard into the array? a. void input(int &array[ ], int numElements, int MAX_SIZE); b. void input(int array[ ], int numElements, int MAX_SIZE); c. int array[ ] input(int array[ ], int &numElements, int MAX_SIZE); d. void input(int array[ ], int &numElements, int MAX_SIZE)

void input(int array[ ], int &numElements, int MAX_SIZE);


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

Chapter 13 - The Rise of the Middle Ages - World History - 10th Grade - Antonian College Preparatory High School

View Set

AZ-900 Azure Fundamentals Practice Questions

View Set

Biol 114 unit 3: Sickle-Cell Disease

View Set

11.4 strategic control and reward systems

View Set

Bayes-Machine Learning: Mid-term

View Set