c++ pointers help

Started by
30 comments, last by nbertoa 16 years, 1 month ago
Yup. The inquiry "can you guys plz explain pointers to me" is waaay too broad for anyone to give you a meaningful response. Hence, you received subtle STFW responses.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Advertisement
in that case, how do i delete this topic
Oh, and just a small tip: It's you, and not 'u'. It's please, and not 'plz'.

Most people here are highly allergic against this MSN kiddie speak, and will not even consider your question if you write like this. So I would suggest you make an effort on spelling correctly before attempting to learn about pointers.
Quote:Original post by Yann L
Oh, and just a small tip: It's you, and not 'u'. It's please, and not 'plz'.

Most people here are highly allergic against this MSN kiddie speak, and will not even consider your question if you write like this. So I would suggest you make an effort on spelling correctly before attempting to learn about pointers.


Thank you for the tip. Wow, I am learning a lot tonight.
int q, *p = &q;*p = 5; // q is now 5


I've shown you how to use a pointer and what it can do, but you most likely won't understand the full potential until you read a C++ book or research it yourself. By the way, it's highly recommended that you read a programming book. Most of us won't spoon-feed you! It took us many years of experience, experimenting, and trial and error to learn this stuff ourselves, why should you be any different? You can better understand a programming language if you do your own research, and learn at your own pace. There's also lots of tutorials online that can help you on your way, and if you have trouble understanding it; come back to it later -- you'll see things you didn't before!

If you need help searching for tutorials, try looking for keywords such as "C++ tutorials".

Regards
_fastcall


Yeesh.

Anyways, since the chastisement against txtspk was done and heard, I'll see what I can provide about pointers. Which is unusual since raw pointers aren't too often used.


First, an analogy. Do you know how web sites, and web links work? If not do a quick search and come back.

Okay. Pointers are to data what links are to sites. They aren't the whole site, but if you follow one you can get the whole thing. If the site content changes, the link isn't invalidated. If the server is down (the data is deleted), or if the url is bogus (bad/null pointer) then following the link will break (very bad stuff in C/C++). And the link is very small compared to the whole site.

Syntactically:

Type *Variable;    // declare a pointer of Type*pointer;          // 'Dereference' the pointer (like following a link, this is how to get at the data the pointer references.&data             // This returns a pointer to the data in question.pointer = &data   // pointer points to data now.pointer->member;   // get a member of data (-> is like . is for data)


There are other nuances to it, but the key concept to grasp isn't the syntax, but the 'link' idea. Why they're useful, how they break, what to not do.

And remember, pointers are useful to learn, but in practice smart pointers or references are almost always preferable.
Quote:Original post by rpstaekwondo
plz explain pointers to me


Ok.. ok.. So the harddrive is made up of millions of little 'switches' of silicon which is a mixure of (IIRC) sand metal and rubber. These switches form to hold data known as 'bits' and the bits for to make data known as 'nibbles' which in return make data known as bytes then intergers, floats, doubles.. etc.. Now this data is all accessed 'randomly', and yes its not just the RAM that accesses the memory this way but the hardrive and most everything do this too, now by random I dont mean it looks at spo 23, 1347, 9132.. etc intill it gets to the right spot but that it does not go from 1, 2, 3.. etc.

now machines do not understand our code but rather a code known as binary. And in the case of most languages the source code in converted into binary by first being parsed to asembly and then being compiled like so. so if you tell your machine to say 'hi' I gets '0110100001101001' this is stored in space on the ram (and maybe harddrive) and a pointer points to this place in the memory. It is also good to know that the size of the pointer changes based on the system, AFAIK, so that a 16bit system only has a 16bit pointer, while a 64bit system will have 64bit pointers..
watch the video here. http://cslibrary.stanford.edu/104/

In short, they point to things.

I'm ready to explain...

but, I fear, if you get addicted to the habit of "taking help",
rather than "Let me struggle" kind of attitude.

Once you promise me that, you are not going to ask me to write programs or do your job, sitting beside you in your office/exam hall, since you are busy, polishing your nails...

I'll explain what ever you ask, if I know what you are asking.

[Edited by - Saughmraat on March 5, 2008 3:47:09 AM]
Gents nandu Intelligents veyrayaa
Quote:Original post by rpstaekwondo
WTF CAN NOBODY ANSWER MY QUESTION???????????????????????????????????????????????????????????????????????


This is way out of the line.
Did you at least click the links that were given to you by the others?

This topic is closed to new replies.

Advertisement