Thread: Pointer to pointer inderction question !!!?!?!?!

  1. #1
    Registered User
    Join Date
    Feb 2017
    Posts
    5

    Pointer to pointer inderction question !!!?!?!?!

    Is it possible to change the value of let's say ***ppptr , to reflect the address of the orignal and 1st pointee, so it would point directly point to it

    Thank YOU
    Last edited by n@bu; 02-14-2017 at 08:48 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The type would be wrong. Just create another pointer of the correct type that points to the original object.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2017
    Posts
    5
    That is exactly the warning that I got when compiling, but I was trying to see, if I could get around it by typecasting or something like that...
    I will.

    Thanks a lot

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by n@bu View Post
    I was trying to see, if I could get around it by typecasting or something like that.
    It's really not very useful. And not necessarily portable. But:
    Code:
    #include <stdio.h>
    
    int main() {
        int    n    = 42;
        int   *pn   = &n;
        int  **ppn  = &pn;
        int ***pppn = &ppn;
    
        pppn = (int***)*pppn;
        pppn = (int***)*pppn;
    
        printf("%d\n", *(int*)pppn); // but what's the point???
    
        return 0;
    }

  5. #5
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by algorism View Post
    It's really not very useful. And not necessarily portable. But:
    Code:
        pppn = (int***)*pppn;
        pppn = (int***)*pppn;

    // What's the point, indeed?

  6. #6
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    I saw some code on the Daily WTF, that was like this:

    Code:
    a=1;
    a=1; // REALLY make sure a == 1.
    Of course, the expressions of a and "1" were more complicated, but I think the point was clear.

    I know you probably just made a typo, ... I'm just joshing you. It's all good in the hood.
    Last edited by MacNilly; 02-15-2017 at 01:49 AM. Reason: things

  7. #7
    Registered User
    Join Date
    Feb 2017
    Posts
    5
    Very insightful. Thank you guys. Coming from a language where referencing/dereferencing is taken care of by the language itself. I was trying different things with pointers, to understand its powers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about freeing pointer to pointer
    By Alpo in forum C Programming
    Replies: 2
    Last Post: 05-07-2014, 09:27 PM
  2. Replies: 3
    Last Post: 10-30-2009, 04:41 PM
  3. Replies: 4
    Last Post: 08-27-2007, 11:51 PM
  4. pointer question.... pointer theory?
    By panfilero in forum C Programming
    Replies: 6
    Last Post: 11-12-2005, 02:29 AM
  5. pointer to pointer as argument question
    By Lateralus in forum C Programming
    Replies: 4
    Last Post: 07-21-2005, 05:03 PM

Tags for this Thread