Thread: pointer stuff

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    50

    pointer stuff

    Sometimes when I'm taking tutorials or looking at someone elses code, I realize that they sometimes have this
    Code:
     **ptr
    or
    Code:
     *( ptr

    ... What does two pointers do, does it point to a pointer that it is itself. I keep trying to remember the definition of this statement but I never can get a good definition that I would stick into my brain...

    Why do you need parenthesis as well, does that put a point FIRST, or?

    thanks
    jay

  2. #2
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Well I don't know about the one with parentheses, but the first one (**ptr) is a pointer to a pointer, meaning ptr holds the address of another pointer.

    Therefore, **ptr retreives the value in the pointer pointed to by ptr.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    So

    Code:
    int x = 5;
    int *p = &x;
    int **pp = &p;
    
    // prints "555"
    cout << x << *p << **pp;

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Don't think of it any differently than you think of a normal pointer. A pointer is, after all, just another data type. So, the syntax 'X* ptr' creates a pointer to something of type X, which could be: an int, a char, a user-defined type, an int* (or any other pointer)... it is all the same.

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 02:36 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  4. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 09:40 PM
  5. Pointer validity check
    By Carlos in forum Windows Programming
    Replies: 6
    Last Post: 12-11-2003, 03:40 AM