Advertisement

Pointers?

Started by January 25, 2002 03:56 PM
10 comments, last by Tac-Tics 22 years, 10 months ago
I''m a begining programmer and I''m having some troubles. I''m taking class in C++ this year in school, but my teacher is new to the language and my textbook looks like it was written in machine code =-/ I also picked up a book on programming in Java and I find it all very interesting (despite the fact it''s only slightly easier to understand than my C++ text). And currently, I know more about Java after studying it for half a month than I know about C++ which I''ve been learning for a quarter of a year. However, Java is obviously very simplified when compared to C++ and I''m having problems understanding the more technical concepts of the language. So after all this, finally, here''s my question. What is a pointer? I have only a slight, misty-eyed understanding of what they could be. My teacher described a pointer as something that "points" to a memroy address (or something, but the point is he said it "pointed" instead of explaining what that REALLY means). Any help would be appriciated. "I''''m not evil... I just use the power of good in evil ways."
A pointer stores the address of the memory that stores the value.

int x = 10; // store 10 in x
int *p = &x // assign the address of x to p

The best way to learn pointers is to play around with them a lot. Here are some urls:

http://www.codeproject.com/cpp/pointers.asp
http://www.mathtools.net/C++/Pointers/
http://www.cplusplus.com/doc/tutorial/tut3-3.html

There are thousands more listed at google.

HTH
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Advertisement
Pointers can be pretty tough to grasp for newcomers but once it clicks it makes alot of sense. Just remember, all a pointer does is point to a location in memory. I can think of many situations where this could speed up a particular operation or provide an easier way to do a lengthy task.

Try this link for a decent explanation:
http://richardbowles.tripod.com/cpp/cpp18.htm

There are a ton more like this all across the web, do a search for "C/C++ Pointers" or something like that and you''ll find many examples. Hope this helps.






~Venome
~Venome
There are many times in your life you''ll have what is called an "enlightening experiance". As far as software engineers and programmers go...that''s how it works with pointers. One day the teacher is explaining them, 6 months down the road BAM it finaly hits you. The point being no matter how well we explain this, it may take some time before you can grasp the concept.

With that in mind.... Let me try to explain to you with a real world example.

A pointer is like a road sign. It points you towards the location however it is not the location itself.

Example: My location is Austin Texas. The road sign I''m looking at says "Austin 11 miles". Is the road sign Austin Texas? No however it tells me how to get there, and if I follow the signs I''ll eventualy arrive at my destination. That''s how pointers work.

The pointer contains the address of where the data is stored. It''s just like a road sign that the computer follows with out your help.

I hope this clears things up a bit for you...If not don''t worry too much. Just keep working with pointers and the day of enlightenment will soon be apon you.
quote: Original post by Anonymous Poster
Example: My location is Austin Texas. The road sign I''m looking at says "Austin 11 miles". Is the road sign Austin Texas? No however it tells me how to get there, and if I follow the signs I''ll eventualy arrive at my destination. That''s how pointers work.

only a helluva lot faster...

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
What Venome and the AP are saying may sound far fetched, but it is very true. You'll know when it happens .



Edited by - Null and Void on January 25, 2002 6:52:52 PM
Advertisement
here''s a great tutorial on pointers, i suggest
you check it out
-eldee;another space monkey;[ Forced Evolution Studios ]
for (int i = 0; i < numberOfPeopleWhoResponded(); i++)
{
cout >> "Thank you very much!\n";
}

=-)
-> http://www.cplusplus.com/doc/tutorial/tut3-3.html
This site will be indefinitely helpful for figuring out those abstract C++ concepts I do not yet comprehend.

Also, I think I found the problem with newbies like me having difficulty with pointers. Such instances like this (which I found in another one of the tutorials):
"Pointers are unusual variables as they simply point to other variables."

I draw your attention to the fact they define a "pointer" as something that "points to another variable". Remember in elementary school when you''re taught not to define a word with itself? Well, maybe all that pointer math gets to the programmer''s brains, which isn''t all that helpful to the students =-)

Again, thanx you, everyone, for all your help.

"I''''m not evil... I just use the power of good in evil ways."
I'm kinda sad, none of my diagrams came out correctly each time i re-posted this, then i realized that you already got the idea, and i had just missed that message. Oh, well, I'm glad you get the idea.

~ Happy Coding ~

Edited by - DragonSoft on January 25, 2002 7:29:15 PM
~ The Dragon Is Feared By Many ~
Oh, here, this example is even worse:
"Pointers are basically the same as any other variable. However, what is different about them is that instead of containing actual information, they contain a pointer to the memory location where information can be found. "

"Pointer are the same as any other variable... They contain a pointer to..."

Wow, it turns out pointers contain themselves =-/ That''s a trick.

"I''''m not evil... I just use the power of good in evil ways."

This topic is closed to new replies.

Advertisement