Thread: Quick Question (I hope)

  1. #1
    Registered User DocDroopy's Avatar
    Join Date
    Jul 2002
    Posts
    32

    Question Quick Question (I hope)

    Can someone explain the difference between ref and val? I think I am getting them mixed up when I am trying to use them, and was hoping someone might be able to clear this up for me. Any help is greatly apprecaited.

    Thanks
    DD
    "aut vincere aut mori"

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    I'm not sure what you mean, I don't know of any ref or val in C that wouldn't be user defined. Unless you're talking about something like this
    Code:
    int v = 2;
    In the above code, 2 is a value and v is a reference to that value
    Code:
    v:
      -----
      |   | ---> 2
      |   |
      -----
    Or v contains that value, you can think of it however you want really as long as you understand that v is the access point for the value 2. :-)
    Code:
    v:
      ------
      | 2  |
      |    |
      ------
    *Cela*

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Are you meaning pass by reference and value?

    To pass by reference you pass a pointer to the "thing" in question. This allows the called function to modify the "thing" (via the pointer)

    To pass by value, you pass a copy of the "thing" itself. The original "thing" is safe, ie cannot be seen/modified by the called function.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>To pass by reference you pass a pointer to the "thing" in question.
    That's not actually pass by reference though, it only simulates pass by reference because the pointer references the original object, but the pointer itself still gets passed by value. A copy is made of the memory location so you can still access the original object. But maybe that's picking nits a little too much :-)
    *Cela*

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>it only simulates pass by reference
    True, that it does. I was just trying to keep things simple

    >>But maybe that's picking nits a little too much
    Nah, it's always good to have other views.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User DocDroopy's Avatar
    Join Date
    Jul 2002
    Posts
    32

    Smile Thanks

    Thanks guys that what I was looking for. I have been offline for a bit, and am trying to get myself back up to speed with C. I was reading a book that was talking about ref and val (reference and value), but it did not explain it at all, so I was getting confused. Again I appreciate the help.

    DD
    "aut vincere aut mori"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  2. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  3. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  4. Quick Question on File Names and Directories
    By Kyoto Oshiro in forum C++ Programming
    Replies: 4
    Last Post: 03-29-2002, 02:54 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM