Pointer confusion

Programming, for all ages and all languages.
Post Reply
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Pointer confusion

Post 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.
This was supposed to be a cool signature...
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post 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 :)
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post 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.
This was supposed to be a cool signature...
User avatar
Telgin
Member
Member
Posts: 72
Joined: Thu Dec 20, 2007 1:45 pm

Post 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.
Post Reply