Hello, please tell me how it works? Suppose there is such a function:
void foo(int &one, int two){ one = two; } int s1 = 1; int s2 = 2; foo(s1, s2); How does an ampersand work before the parameter of the one function? I understand that the function works with a variable that is allocated in static memory. It turns out that we pass a value of type int to the function, then we take its address. But why in the body of a function can we work with it as with a normal variable, and not as with a pointer? In theory, it would be necessary to dereference.
This design is clear:
void foo(int* one, int two) { *one = two; } and when the function is called, we pass the parameters (&s1, s2); .