When you call a function, arguments that are passed to the function are passed-by-value if they are not arrays or not deliberately passed-by-reference with the ampersand (&) symbol. For instance,
void boo (int a, int b) {}
int main() {
int var1 {1};
int var2 {2};
boo(var1,var2);
return 0;
}
In this scenario, values of the integer variables var1 and var2 are copied to the function parameters a and b and stored in the stack frame allocated for the boo() function. My questions are:
If I write
void boo (int a, int b) {}
int main() {
boo(1,2);
return 0;
}
are the integer literals 1 and 2 not stored in the main() stack frame since they are now r-values?
If I instead write
void boo (int &a, int &b) {}
int main() {
int var1{1};
int var2{2};
boo(var1,var2);
return 0;
}
are the parameters a and b still stored in the stack frame of the boo() function as a some kind of a back-up etc. Or are they only references to the actual parameters var1 and var2 now?