|
 |
Darren New wrote:
> Warp wrote:
>> Darren New <dne### [at] san rr com> wrote:
>>>>> My point is that if you do
>>>>> a = 5; b = a; a = 7;
>>>>> you're not changing the value in b.
>>>> Of course you are. You are changing it to 5.
>>
>>> Right. You're not changing the value in b when you assign 7 to a.
>>
>> Uh? That's because you are changing the value of a, not the value of b.
>
> Yes! Precisely. You're not changing the value of 5. You're changing the
> value of 'a'.
Or, maybe more clearly....
a = 5; b = a; a++;
This doesn't change the value in 'b'. You're not incrementing the value in
'a'. You're replacing the value in 'a' with a new value. Numbers are so
familiar that you don't normally think of '5' as being an instance of an
object, so it's hard to separate object from variable in ones mind with
integers. That's why I gave the string example.
Note that in FORTRAN, the equivalent code would actually change the value in
'b' as well. (As in, all arguments get passed by reference, and you can
actually change the storage location where the literal '5' is held, and you
get screwed. Obviously not in all FORTRAN implementations, but...)
--
Darren New, San Diego CA, USA (PST)
There's no CD like OCD, there's no CD I knoooow!
Post a reply to this message
|
 |