final159

final159 - Use the program below for problems 1 3 1 2 3 4 5...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Use the program below for problems 1 – 3 1 #include<stdio.h> 2 3 #define SIZE 5 4 5 void initArray(int[]); 6 7 int main() 8 { 9 int x[SIZE] = {1, 3, 5}; 10 11 printf("%d ", x[2]); 12 13 initArray(x); 14 15 printf("%d\n", x[2]); 16 17 return(0); 18 } 19 20 void initArray(int y[]) 21 { 22 int lcv; 23 24 for(lcv = 0; lcv < SIZE; lcv++) 25 { 26 y[lcv] = lcv + 1; 27 } 28 } 1. What is the output of the the program provided on the left? A. 5 5 B. 3 3 C. 5 3 D. None of the above 2. Which of the following is stored in the array at index 3 before the call to the initArray function? A. 0 B. 5 C. 7 D. None of the above 3. Which of the following would NOT be a possible outcome of changing the relational operator in the loop control expression on line 24 from less than to less than or equal to? A. The compiler would issue a warning. B. The program will crash. C. The output will be unexpected. D. None of the above 4. Which of the following statements regarding arrays is FALSE? A. All of the elements in an array in C share the same data type. B. All of the elements in an array in C share a single variable name, but a different index value. C. An array element, in C, cannot be accessed if it has not been initialized. D. None of the above Use the code below for problems 5 – 6 #define EXIT -1 #define MAXSIZE 10 int getData(int x[]) { int lcv = 0; do { printf("Enter data #%d: ", lcv + 1); scanf("%d", &x[lcv]); lcv++; }while(lcv < MAXSIZE & x[lcv - 1] != EXIT); return(x[lcv - 1] != EXIT ? lcv : lcv – 1); } 5. Which of the following is returned from the function on the left if 10 non- negative integer values have been input by the user? A. 6 B. 7 C. 10 D. None of the above 6. Which of the following is returned from the function above if 9 non-negative integer values have been entered before the user enters the EXIT value? A. 8 B. 9 C. 10 D. None of the above
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Use the code segment below for problems 7 – 8 int temp; int lcv; int array[SIZE] = {8, 4, 1, 2, 7, 5}; for(lcv = 0; lcv < SIZE / 2; lcv++) { temp = a[SIZE - 1 - lcv]; a[SIZE - 1 - lcv] = a[lcv]; a[lcv] = temp; } 7. Given that SIZE has been defined as 6, which of the following is found in index 3 after the code above has been executed? A. 2 B. 1 C. 7 D. 4 8. Which of the following would be found in index of the array 3 if the loop control expression was changed from lcv < SIZE / 2 to lcv < SIZE after the code segment above was executed? A. 2 B. 1 C. 7 D. 4 Use the code below for problems 9 – 10 int x[5] = {3, 4, 5, 6, 7}; int lcv; int temp; temp = x[0]; for(lcv = 0; lcv < 4; lcv++) { x[lcv] = x[(lcv + 1) % 5]; } x[lcv] = temp; printf("x[0] = %d\n", x[0]); printf("x[4] = %d\n", x[4]); 9. What is the output of the first print statement above? A.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

final159 - Use the program below for problems 1 3 1 2 3 4 5...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online