I'm maintaining some C code that was written by the person who had my job last. A situation has come up regarding passing by reference. Here's a shortened, contrived example of what I'm working with:
static int b;
void SetToTen(int *a){
b = 10;
/* >>>>>>> Need to set a equal to b on this line <<<<<<<< */
return;
}
int main{
int a = 0;
SetToTen(&a);
/* Now a should be equal to 10*/
.
.
.
return 0;
}
In the SetToTen function, I could either write:
*a = b;
OR
a = &b;
I think these two are functionally equivalent (a will be equal to ten with either of them.) But my question is: are there any sneaky subtleties associated with one over the other? Specifically, if I use a = &b does that mean that if I change b in the future, a will change as well? And is this not the case if I use *a = b?
Thoughts/Musings/Comments would be appreciated.