Pointers

This is a discussion on Pointers within the C++ Programming forums, part of the General Programming Boards category; Could someone please explain to me exactly how pointers work? For some reason I'm not getting it. I read the ...

  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,796
    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 02: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, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21