hi everyone. i'm reviewing for my final and my teacher posted this as a sample final question.
What would the following block of code output?
Code:
#include <iostream>
using namespace std;
void fun1(int w, int& x, int a[]);
int main()
{
int a = 1, b = 5;
int c[7];
c[0] = 10;
fun1(a, b, c);
cout << "\nMain: a=" << a << " b=" << b << " c[0]=" << c[0];
return 0;
}
void fun1(int w, int& x, int a[])
{
cout << "\nFun1: w=" << w << " x=" << x << " a[0]=" << a[0];
w = 100;
x = 200;
a[0] = 300;
}
the answer is:
Code:
Fun1: w=1 x=5 a[0]=10
Main: a=1 b=200 c[0]=300
i'm not quite clear on why the answer is what it is and it'd be great if someone could explain to me the answer. thanks!