Reference no: EM13165469
What output would be produced by the following program segment?
................
void fn(int &, double &); // function prototype (pass-by-reference)
void fn(int, int); // function prototype (pass-by-value)
int main()
{
int integer1 = 4, integer2 = 3;
double sum = 1.5;
fn(integer1, integer2);
cout << "integer1=" << integer1 << ", integer2="
<< integer2 << ", sum=" << sum << endl;
fn(integer1, sum);
cout << "integer1=" << integer1 << ", integer2="
<< integer2 << ", sum=" << sum << endl;
return 0;
}
void fn(int &x, double &y)
{
x -= 2;
y = x*y;
cout << "y=" << y << endl;
}
void fn(int x, int y)
{
x -= 3;
y = x*y;
cout << "y=" << y << endl;
}
10 What output would be produced by the following lines?
.....
void fn();
int main()
{
cout << "First call to function:\n";
fn();
cout << "\n\nSecond call to function:\n";
fn();
cout << endl;
return 0;
}
void fn()
{
static int array1[3] = {2, 1, 3};
cout << "\nValues on entering fn:\n";
for (int i=0; i<3; i++)
cout << "array1[" << i << "] = " << array1[i] << " ";
cout << "\nValues on exiting fn:\n";
for (int i=0; i<3; i++)
cout << "array1[" << i << "] = "
<< (array1[i] += 2) << " ";
}