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
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"
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
In the above code, 2 is a value and v is a reference to that valueCode:int 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 | | -----
Code:v: ------ | 2 | | | ------
*Cela*
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]
>>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*
>>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]
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"