PDA

View Full Version : C++ question



wo1olf
January 20th, 2006, 10:15 AM
i'm reading this (http://www.cplusplus.com/doc/tutorial/pointers.html) tutorial on c++ but i'm getting confused with pointers et the dereference and reference operator. Any one know where i can find explanations of those concept but that are more easily to understand?

NiñoScript
January 20th, 2006, 02:29 PM
all the c tuts ive read in my life explain it the same way (-:


& is the reference operator and can be read as "address of"
* is the dereference operator and can be read as "value pointed by"


... ill try to explain it again with normal stuff to see if you understand:

I am NiñoScript, and i like the number 3 (NiñoScript = 3)
I live in the number 1329 of this street (&NiñoScript == 1329 //true)

see?
now ill make a pointer that points to my adress:

My house is the same number as my adress (house = &NiñoScript)
soo, my house is the same as 1329 (house == 1329 //true)
now, i want to know if i live in my house (*house == NiñoScript //true)
that means, that the number the guy who lives in my house likes, is 3 (*house == 3 //true)

if you want to know what is happening, when you read, change * with "value pointed by", and & with "adress of", just as your tut said


another thing, i'm not sure if this is possible, but its a good example anyway:
NiñoScript = 3 (me likes 3)
NiñoScript == *&NiñoScript //this should be true

do you understand why it should be true?
if im equal to 3, then whats equal to the guy who lives in (*) my house(&)? it should be equal to 3 :)


hope that helped :pleased: