Even in C++ the sign &
does not denote an address in a declaration. It denotes a reference.
This declaration in C++
void square(int &x){
//...
}
means that the function accepts its argiment by reference.
In C passing by reference means passing an object indirectly through a pointer to it. So dereferencing a pointer within a function you get a direct access to the original object passed to the function through the pointer.
So this function in C++
void square(int &x){
x = x * x;
}
accepts an object of the type int
by reference.
In C this function
void square(int *x){
*x = *x * *x;
}
accepts an object of the type int
by reference indirectly through a pointer to it.
Pay attention to that the assignment statement in the second function
void square(int *x){
x = (*x) * (*x);
}
is incorrect. You are trying to assign an integer expression to a pointer. You have to write
*x = *x * *x;
as already shown above. That is you need to change the passed object of the type int
to the function indirectly through a pointer to it.