Content Frame
Note for screen reader users: There is text between the form elements on this page. To be sure that you do not miss any text, use item by item navigation methods, rather than tabbing from form element to form element.
Skip Breadcrumb Navigation
Home  arrow Student Resources  arrow Quizzes  arrow Chapter 5

Chapter 5

Arrays

This activity contains 10 questions.

Question 1.
Given the following array declaration, which snippet of code outputs all elements in the array?

int arr[5];

 
End of Question 1


Question 2.
Which of the following correctly declares an array that holds exactly 10 integers?

 
End of Question 2


Question 3.
Given the following function prototype:

  void foo(int arr[]);

Which statement correctly passes the array to the function?

 
End of Question 3


Question 4.
What will the following snippet of code output?

void foo(int arr[])
{
  arr[1]=1;
  return;
}

int main()
{
  int arr[] = {3, 2, 1};
  foo(arr);
  cout << arr[0] << " " << arr[1] << " " << arr[2];
  return 0;
}

 
End of Question 4


Question 5.
Which of the following is considered the best way to output all values inside an array that is passed to a function?

 
End of Question 5


Question 6.
What will the following snippet of code output?

void foo(const int arr[])
{
  arr[1]=1;
  return;
}

int main()
{
  int arr[] = {3, 2, 1};
  foo(arr);
  cout << arr[0] << " " << arr[1] << " " << arr[2];
  return 0;
}

 
End of Question 6


Question 7.
Which of the following is an invalid function prototype to accept a two-dimensional array of type double?

 
End of Question 7


Question 8.
What will the following snippet of code output?

int a[5];
a[0]=1; a[1]=2; a[2]=3;
for (int i=0; i<5; i++) {
   cout << arr[i] << endl;
}

 
End of Question 8


Question 9.
What is the output of the following code?

int a[] = {1,2,3,4,5};
int i = 0, j = 4, temp;
while (i<=j) {
  temp = a[i];
  a[i] = a[j];
  a[j] = temp;
  i++;
  j--;
}
for (i=0; i<5; i++) {
   cout << a[i] << endl;
}

 
End of Question 9


Question 10.

Which of the following functions will correctly "delete" the element in the array at position p by shifting each array element down one slot?

For example, given the following code:


int a[] = {1,2,3,4,5};
int numelements = 5;

deletenumber(a,2,numelements);
for (int i=0; i<numelements; i++) {
   cout << a[i] << endl;
}

The output should be:


1
2
4
5

To "delete" number 3 which is stored in position 2.

 
End of Question 10





Pearson Copyright © 1995 - 2010 Pearson Education . All rights reserved. Pearson Addison Wesley is an imprint of Pearson .
Legal Notice | Privacy Policy | Permissions

Return to the Top of this Page