Will somebody please explain value parameters to me!!!

Reply

Join Date: Jan 2005
Posts: 1
Reputation: EyeNeedHelp is an unknown quantity at this point 
Solved Threads: 0
EyeNeedHelp EyeNeedHelp is offline Offline
Newbie Poster

Will somebody please explain value parameters to me!!!

 
0
  #1
Jan 6th, 2005
I am so lost! I just need somebody to explain what to do and how it works.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Will somebody please explain value parameters to me!!!

 
0
  #2
Jan 6th, 2005
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:

  1. void Test( int byValue, int& byReference )
  2. {
  3. byValue++; // this changes the local version, but doesn't affect the caller
  4. byReference++; // this changes the caller's variable too
  5. printf( "inside TEST value=%d, ref=%d\n", byValue, byReference );
  6. // this prints 2 for both since they were passed in as 1 in our call shown below...
  7. }
  8. ...
  9. int byValue = 1, byReference = 1;
  10. Test( byValue, byReference );
  11. printf( "after TEST value=%d, ref=%d\n", byValue, byReference );
  12. // this prints 1 and 2, because Test() changed the byReference one but not the byValue one.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC