17.06.2017, 18:29
The ampersand (&) means that a variable is passed "by reference" which means the function can alter the original variable. Unlike variables that are passed "by value" (the default) where - in a sense - a copy of the original variable is sent instead. For example:
In the case of strtok, the idx (index) variable stores the position where a space was encountered. So if strtok is called again with the same idx parameter (which now does have a value) it will start its search from that position onward. However, strtok is horribly outdated. Don't use it. Use sscanf instead.
PHP Code:
main()
{
new byref;
printf("%d", byref); // prints 0
DoSomethingWithByRef(byref);
printf("%d", byref); // prints 5
}
DoSomethingWithByRef(&value)
{
value = 5;
}