Ah, so you don't know the difference between call by reference and call by value yet?
Alright, let's compare these two functions:
1 2 3 4 5 6 7 8 9 10 11
|
void callByValue(int value)
{
value = 5;
return 0;
}
void callByReference(char[] cstring)
{
cstring[0] = 'a';
}
|
The first function will do absolutely nothing, whereas the second one will actually change the array passed to it (oh well, or crash your program under some circumstances).
The difference is what is passed through the function:
in callByValue, we pass an int. But we are passing the
value of the int, not the int variable itself. That also goes for arrays. However, arrays are implicitly
pointers to
memory regions - which means they are basically numbers that tell you when in the memory their data is located. Which means if you pass an array to a function, you don't really pass the array, you pass the location of the array. This allows getPeople to operate on the actual data instead of on copies of it.