Pointers

Grant Edwards grant at nowhere.
Thu Mar 23 17:59:00 EST 2000


In article <38DA9F8C.E9133C71 at be-research.ucsd.edu>, Curtis Jensen wrote:

>Python does work on a reference setup, but it's not exactly
>like pointers.  For example:

>>>> a = 5
>>>> b = a
>>>> a = 3
>>>> print b
>5
>
>If b were a pointer to b then print b would return 3, not 5.  

No, b isn't a pointer to a.  b is a pointer to whatever a was
pointing to when the assignment a = b was made.  It's the same
as pointers in C:

const int object5 = 5;
const int object3 = 3;

a = &object5;
b = a;
a = &object3;

b points to object5, and a points to object3. *a == 3 and *b ==
5 just like Python.

>There is the problem of mutable types and immutable types here,
>but the same thing occurs if you use a mutable type.  So,
>pointers and python referances are not the same.

I'm afraid I still don't see how they're different.

-- 
Grant Edwards                   grante             Yow!  I want the presidency
                                  at               so bad I can already taste
                               visi.com            the hors d'oeuvres.



More information about the Python-list mailing list