954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Will somebody please explain value parameters to me!!!

I am so lost! I just need somebody to explain what to do and how it works.

EyeNeedHelp
Newbie Poster
1 post since Jan 2005
Reputation Points: 10
Solved Threads: 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.
Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You