I have a trouble with references. Consider this code:
void pseudo_increase(int a){a++;}
int main(){
int a = 0;
//..
pseudo_increase(a);
//..
}
Here, the value of variable a
will not increase as a clone or copy of it is passed and not variable itself.
Now let us consider an another example:
void true_increase(int& a){a++;}
int main(){
int a = 0;
//..
true_increase(a);
//..
}
Here it is said value of a
will increase - but why?
When true_increase(a)
is called, a copy of a
will be passed. It will be a different variable. Hence &a
will be different from true address of a
. So how is the value of a
increased?
Correct me where I am wrong.