Tuesday, June 20, 2006

when should you pass by reference and by value?

you would pass a variable by value when you don't want the function to change the original value passed in as a parameter.
complex types, such as orrays and strings must be passed by reference since only a pointer to them can be passed in. If you don't want the function to ever change the values of a complex type parameter, you should declare the parameter as const to achieve the effects of passing by value.

0 Comments:

Post a Comment

<< Home