Page 1 of 1

Pointer confusion

Posted: Mon Jan 07, 2008 9:36 pm
by Zacariaz
I know, i should have got the hang of this a long long time ago :oops:

anyway, i have come up with these three pointer rules:

"*ptr" to retrive the data pointed too or to declare a pointer.
"&ptr" to retrive the memory address of a pointer.
"ptr" to retrieve the memory address pointed too by a pointer.

Now i just want to be sure that i'm not missing anything or am making the wrong assumptions.

Posted: Tue Jan 08, 2008 1:10 am
by xyzzy
Yes, that's about right. When you say "to declare a pointer", it needs to be preceded by a type, like char *ptr. Just *ptr wouldn't work to declare a pointer :)

Posted: Tue Jan 08, 2008 2:20 am
by Zacariaz
AlexExtreme wrote:When you say "to declare a pointer", it needs to be preceded by a type, like char *ptr. Just *ptr wouldn't work to declare a pointer :)
Of course, but if thats the only thing, i think im finaly on my way. The think is i dont use pointers very much and tend to forget exactly how they work.

Posted: Tue Jan 08, 2008 6:35 pm
by Telgin
It does take a bit of work to get the hang of using them in C/C++, doesn't it?

I still remember the days where I would just randomly insert &s and *s until my code compiled. :oops: You might well imagine that I never coded with pointers then, but when I copied code from others sometimes a pointer would turn up...

When you start using pointers a good bit and get the hang of them though, you'll be glad you understand how to use them.