Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ekim_Gram

I hate pointers and references!

This topic is 5646 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Right now I''m going through Sam''s Teach Yourself C++ in 21 Days, of course if I did a lesson a day I''d be done by now but I chose to take it slow. I''m up to Day 11: Objectr-Oriented Analysiss and Design but I''m still confused out of my mind about references and pointers. I mostly understran references, I just don''t like them much, I''m guessing I will in time, though. But pointers, uggh, I hate them so much. Can somebody just give me a simple explanation of what they are and what they do? I''ve gone through the pointers chapter about 3 times and I''m gonna go over it again and again, each time I do I understad a little bit more but I just hate them. I know that they are variables that hold memory addresses. But can anybody gimmie an explanation in "dumbass" terms. I''m no dumbass but seriously, that could be the only way I''d be able to get this stuff. There''s no town drunk here, we all take turns.

Share this post


Link to post
Share on other sites
Advertisement
there are plenty of tutorials about pointers on this site...do a search.

Everyone hates pointers when they first start, but then grow to love them.

Share this post


Link to post
Share on other sites
That's it. They're variables that hold a memory address. As for their uses, don't worry about them. Pointers are absolutely essential to most programming problems, and you will find more and more uses for them when you learn more advanced topics.

EDIT: I've never hated pointers. They are very, very simple, if aparrently useless at first. I think it's usually their seeming uselessness that mekes people hate them, not real confusion about what they are. The best thing to do is just to forget about it for the moment. Learn how to use them (not too hard), and you'll find out the why soon enough.

[edited by - micepick on May 1, 2003 7:36:32 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Ecko
there are plenty of tutorials about pointers on this site...do a search.

Everyone hates pointers when they first start, but then grow to love them.



I don''t need tutorials, I just can''t understand them. Maybe your right though, I just gotta wait and see what this book brings me. *Sigh*


There''s no town drunk here, we all take turns.

Share this post


Link to post
Share on other sites
I agree with Ecko,

U start out with hating them, then u grow to love them..
:D

I would recommend to NOT continue with the chapters if you DONT understand pointers..

If you do understand pointers, but hate them or dont see why they are useful then continue with the chapters..

But yeah basically a pointer is a variable that hold memory adresses. If you understand that, then continue with the book.

Share this post


Link to post
Share on other sites
A variable is a memory location. When you store something into a variable (int i = 10; ) the value is stored in that memory location (okay, ya probably already got that much figured out). A pointer, on the other hand, holds a memory address. This address can be changed. For instance, if you were to say "int *ptr = &i", you are taking a reference to "i" (in other words, the memory location of the "i" integer that we declared earlier) and storing it in "ptr". Now, when we access "ptr" we are really accessing "i". However, we can change "ptr" to allow us to access a different variable. For example, "ptr = &j;" stores the memory location of "j" into "ptr". Now when we access "ptr" we are actually accessing "j".

Perhaps you don't see the purpose of this yet, but just trust that there is a use for it. Eventually, you're going to run into a problem and you'll say, "Hey, I can use a pointer for that!" Just be patient with it.

- Jay


[ Here, taste this ]


[edited by - coderx75 on May 1, 2003 7:48:44 PM]

Share this post


Link to post
Share on other sites
Right now you know enough about pointers, they hold memory addresses. As long as you know how to create them and derefrence them then move on.

Most ppl who start learning pointers don''t have a hard time implementing them but why they are there. They hold memory adrresses so what. After a few chapters youll learn why and when to use em. Goodluck.

BTW 90% what I said Micepick has also stated, listen to him.

Jeff D

Share this post


Link to post
Share on other sites
Hi Ekim_Gram,

Maybe you could be a bit more specific in your questions. Fine, we know that you don''t understand pointers, but that''s quite a general statement. You''ve already said there''s some stuff you understand. Perhaps if you skim through the chapter in the book again, and pick out the bits that confuse you, and post them here. A more specific question will get you a more specific answer.

Also remember that sometimes you have to come across a real-life problem before you''ll find a use for a particular feature.

Share this post


Link to post
Share on other sites
I also am currently working with pointer*.[new to programing]
From what i gather it goes like this.Rather than your program
having to make a copy of a variable,store it then copy it back.
wich produces unwanted overhead and slows your program down.
you can use pointers* to dereference (<- fancy name for accessing the info stored at that memeory address).Also the
pointers* must be of the same type.If you declare a pointer* of
type double- you have to point it to a type of double.I hope
this help.Anyone feel free to correct me if im wrong[as i am
only on chapter 6 myself ]

Also if you understand how to write them but are unsure of the
details of pointers*,skip and keep reading.Sometimes things will
become more clear as you read on.(i will usualy read the book
twice)
big

Share this post


Link to post
Share on other sites
Pointer access is slower than "normal" access in most situations
You will need pointers for dynamic memory. References are useful when you want to pass large objects to functions.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!