This is called passing by reference and how the name states it means to pass just a reference of the variable (in this case a char*
).
Either solutions will work fine, what will actually happen is that, when void functionName(char* string)
is called, the address of the first char
in memory will be saved on stack and passed as a parameter to the function.
Consequently any edit to the variable inside the function would edit also the original variable. In this case, since you need to pass an array you just have this option.
For standard types like int
, float
you can distinguish them:
void passByValue(int i);
void passByReference(int &i);
The difference is that in the former case value is copied into stack when calling the function, while in the latter just a reference (pointer) to the value is passed.