2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by Chainsaw
0

There are generally two kinds of parameters to a function, those by VALUE and those by REFERENCE. A VALUE parameter is one where the variable's value (it's contents) are passed to the routine, whereas a REFERENCE parameter is one where the variable's location is passed to the routune.

Here's an example:

void Test( int byValue, int& byReference )
{
    byValue++;  // this changes the local version, but doesn't affect the caller
    byReference++;  // this changes the caller's variable too
    printf( "inside TEST value=%d, ref=%d\n", byValue, byReference );
        // this prints 2 for both since they were passed in as 1 in our call shown below...
}
...
    int byValue = 1, byReference = 1;
    Test( byValue, byReference );
    printf( "after TEST value=%d, ref=%d\n", byValue, byReference );
        // this prints 1 and 2, because Test() changed the byReference one but not the byValue one.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.