functions

#include<iostream>
using namespace std;
short able(short&,short);
void baker(short&,short&);
void charlie(short,short&);
int main()
{
short x=2,y=3,result;
result=able(x,y);
cout<<result<<" "<<x<<" "<<y;
return 0;
}
short able(short&a1,short a2)
{
a1=a1+3;
a2=a2+4;
baker(a1,a2);
return(a1+a2);
}
void baker(short&b1,short&b2)
{
b1=b1+1;
b2=b2-1;
charlie(b1,b2);
}
void charlie(short c1,short&c2)
{
c1=c1-2;
c2=c2-3;

}




Can anyone please tell me how is the value of y is equal to 3 in this program , as I have used call by value for b2 in the function able (short&a1,short b2).
Last edited on
Since the argument a2 in able is passed by value y is not modified
I didn't get it can you please explain ?
Since the argument a2 in able(short&a1,short a2) is a local variable,so the modified value can't be passed back to y.
change a2 to be passed by reference: short able(short &a1,short &a2)
Topic archived. No new replies allowed.