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 4

Chapter 4

Parameters and Overloading

This activity contains 10 questions.

Question 1.
What will the following program fragment output?

void foo(int x)
{
   int y = 4;
   x = 10;
   cout << x << " " << y;
}

int main()
{
   int x=2, y=3;
   foo(x);
   cout << x << "  " << y;
   return 0;
}

 
End of Question 1


Question 2.
What will the following program fragment output?

void foo(int &x)
{
   int y = 4;
   x = 10;
   cout << x << " " << y;
}

int main()
{
   int x=2, y=3;
   foo(x);
   cout << x << "  " << y;
   return 0;
}

 
End of Question 2


Question 3.
What will the following program fragment output?
void swap(int &x, int &y)
{
    x=y;
    y=x;
}

int main()
{
   int x=2, y=3;
   swap(x,y);
   cout << "X=" << x << "  Y=" << y;
   return 0;
}

 
End of Question 3


Question 4.
Which of the following is not allowed in overloading a function?

 
End of Question 4


Question 5.
What is the output of the following code snippet?

void printMoney(int dollars, int cents = 0)
{
   cout << dollars << " dollars and " << cents << " cents.";
   return;
}

int main()
{
  printMoney(2,50);
  printMoney(4);
  return 0;
}

 
End of Question 5


Question 6.
Which of the following statements is most similar to the following?
x = ComputeValue();
assert(x>=0);

 
End of Question 6


Question 7.
Which of the following is not a recommended practice for writing a large program consisting of many functions?

 
End of Question 7


Question 8.
What will the following program output?

void foo(int x);

int main()
{
  int x=1;
  cout << "Before foo, X=" << x;
  foo(x);
  cout << "  After foo, X=" << x;
  return 0;
}

void foo(int x)
{
   x = 2;
   cout << "In foo, X = " << x;
   return;
}

 
End of Question 8


Question 9.
What will the following program output?

void foo(int x);
int x;

int main()
{
  x=1;
  cout << "Before foo, X=" << x;
  foo(x);
  cout << "  After foo, X=" << x;
  return 0;
}

void foo(int x)
{
   x = 2;
   cout << "In foo, X = " << x;
   return;
}

 
End of Question 9


Question 10.
Given a function with a reference parameter such as: void foo(int &x) Which of the following calls would give an error message?

 
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