Guest_imported
New member
- Jan 1, 1970
- 0
Okay, arrays are passed by reference...
So, when I pass the array into a function, and inside
that function, i change the value of the array, now when
i return back to its caller, the value is NOT changed? why?
pass by reference are suppose to change it right?
For example...
void doit(char* msg)
{
msg = "Hi";
}
void main()
{
char* msg = "Hello World!";
doit(msg);
<---- at this point, msg is STILL "Hello World!"
printf("%s\n", msg);
}
WHY? Isnt pass by reference suppose to change msg to "Hi" instead? If not? How do I pass array by reference and CHANGE the value?
I tried using all sorts of functions like memcpy(),
memmove(), strcpy(), etc, and NONE work.
So does anyone know how can i TRUELY pass an array by
reference? I need the value to change and return it back.
(And no, i wish to avoid using a return statement by returning a char*, I want to return by ref)
Thank you.
So, when I pass the array into a function, and inside
that function, i change the value of the array, now when
i return back to its caller, the value is NOT changed? why?
pass by reference are suppose to change it right?
For example...
void doit(char* msg)
{
msg = "Hi";
}
void main()
{
char* msg = "Hello World!";
doit(msg);
<---- at this point, msg is STILL "Hello World!"
printf("%s\n", msg);
}
WHY? Isnt pass by reference suppose to change msg to "Hi" instead? If not? How do I pass array by reference and CHANGE the value?
I tried using all sorts of functions like memcpy(),
memmove(), strcpy(), etc, and NONE work.
So does anyone know how can i TRUELY pass an array by
reference? I need the value to change and return it back.
(And no, i wish to avoid using a return statement by returning a char*, I want to return by ref)
Thank you.