So I have this recursive and I know the output if it is passed by ref or value, and I know the difference, I still just don't understand why the answers for each pass by val and ref(only x is passed by ref). can someone help me map this out?
output by ref: output by val:
6 2 6 2
7 1 7 1
8 0 8 0
8 0 8 0
8 1 7 1
8 2 6 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void recurse (int& x, int y);
int main(){
int a=5,b=3;
recurse(a,b);
return 0;
}
void recurse(int& x, int y){
if(y>0){
x++;
y--;
cout<<x<<" "<<y<<endl;
recurse(x,y);
cout<<x<<" "<<y<<endl;
}
}