Hello guys, I am utterly confused about functions. Neither, my professor or the text book did a good job of explaining the exact structure and happenings of function paramaters. On a recent test I had a pece of code that looked like the one I posted below this. I got the question wrong and when I compiled it at home the value of the final variables was a=7, b=1, c=8.
Could someone please explain to me how this works, and maybe a method of tracing the variables?
thanks a bunch,
axon
Code:
#include <iostream>
using namespace std;
int a;
int b;
int c;
void c1(int b, int a)
{
a+=1;
b+=1;
c+=1;
}
void c2(int b, int& a)
{
a+=3;
b+=3;
c+=3;
}
void c3(int c, int& b)
{
a+=3;
b+=3;
c+=3;
}
int main()
{
a=b=c=1;
c1(a, b);
c2(b, c);
c3(c, a);
cout << "the value of the variables is: ";
cout << a << " and " << b << " and " << c <<endl;
return 0;
}