Thread: Pointers

  1. #1
    Novice C++ Programmer
    Join Date
    Nov 2003
    Posts
    96

    Pointers

    Could someone please explain to me exactly how pointers work? For some reason I'm not getting it. I read the tutorial here all thoroughly but I'm still left in the dust.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    My best code is written with the delete key.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Thumbs up Nice, Prelude!

    My standard "homework" analogy...

    Sally doesn't know the answer to the homework, but she knows who does... Sally is a pointer. Bob has the answers, but you don't know that... maybe you don't know where Bob lives. (In a program, Bob doesn't have a name, only an address).

    If you ask Sally what she knows, she will give you Bob's address:
    Answer = Sally; // Answer now equals Bob's address... not what you want

    You can tell Sally to go get the answer.
    Answer = *Sally // Answer now equals the real answer.

    The most common use for pointers is when a function needs to modify or return more than one value. For example, when you need to modify a string.
    Last edited by DougDbug; 11-21-2003 at 03:02 PM.

  4. #4
    Registered User Red Haze's Avatar
    Join Date
    Nov 2003
    Posts
    30
    Sparknotes has some good pointer tutorials, with nice visuals:

    http://www.sparknotes.com/cs/
    ----[Red Haze]----

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM