[gameprogrammer] Re: Books for mastering C++ pointers

In trying to teach pointers to new programmers I find that there are a
couple of things that are horribly confusing about them to most
people. The first one is that if you are using C/C++ or any language
derived from them the syntax for declaring a pointer is ....
mystifying. I've been coding in C since '81 and if I want to get to
declare a pointer to a function and get it right the first time I find
a piece of code with a similar declaration and modify it rather than
trying to write it from scratch. Even then there is only about a 70%
chance that it will compile the first time....

The second problem seems to be a basic bug built into the hardware of
the human brain. We seem to want to treat the name of a thing as the
thing. When we think, we think using symbols for things. When we think
of an elephant, we may think the word "elephant" or we may visualize
an elephant, but we do not have a real elephant running around in our
minds. So we confuse names and the things they name. (Think about the
way magic uses names and you'll get the idea of how deep the confusion
between a name and a thing can be for many people.)

Ok, so a point is an other name for a value. But, the pointer has its
own name too. You have to start thinking about the names of names and
people already confuse names with the things they name. But, to make
it worse, a pointer is something that is a name that can name one
thing now, and another thing the next time through this loop.

People have a lot of trouble with the idea of a variable because it is
the name of a value that can change. In real life its like telling you
that my girlfriend's name is Joan, but every time you see me I'm with
a different lady. No problem because Joan is the name a variable of
type wife... Now, you meet one of Joan's many values and ask me for
Joan's address (that is you get a pointer to Joan) because you think
this particular Joan is really the kind of woman you like and since
I'm changing girlfriends all the time you figure you won't have to
wait long for me to dump her....

A while later you see me out with a new value of Joan so you call
indirect through your pointer to Joan and are surprised to find
yourself talking to the new Joan! But of course you have a pointer the
Joan, not the the old value of Joan which has been over written. You
really wanted to get the Value of Joan, not the Address of Joan...

Which just goes to show that in all relationships ifs values that
count.... even when when we are being confused of about the difference
between the name of Joan, the address of Joan, and the value of Joan,
or should that be the content of Joan? Content is more precise.

All in all I find it helps to draw a lot of boxes on the board, write
the names off to the sides of the boxes and then write the values
inside the boxes. But, for pointers I put a dot inside the box
connected to an arrow that points to the box the pointer references.
Then you can **SEE** the pointers and interpret what it means to get
an address and what it means to dereference and address.

Lots of pencil and paper work helps.

Most programming is learned a long way away from a computer.

Bob Pendleton

On Tue, Nov 29, 2011 at 11:31 AM, Alan Wolfe <alan.wolfe@xxxxxxxxx> wrote:
> If you get stuck feel free to ask questions here about why something does or
> does not work (:
>
>
> On Tue, Nov 29, 2011 at 5:00 AM, Dipankar Das <deep.napster@xxxxxxxxx>
> wrote:
>>
>> Thank you all for your inputs.  I have been working on pointers but
>> sometime I do get into a state of confusion.  However, I will have a look at
>> the links and book that was suggested and practice more and more.
>>
>> Regards,
>> Dipankar
>
>



-- 
+-----------------------------------------------------------
+ Bob Pendleton: writer and programmer
+ email: Bob@xxxxxxxxxxxxx
+ web: www.TheGrumpyProgrammer.com

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: