Store some addresses of variable to integer variable

This is a discussion on Store some addresses of variable to integer variable within the C++ Programming forums, part of the General Programming Boards category; I want to save address of the pointer point to to my variable: So, I do that: Code: <Pointer>*a; int ...

  1. #1
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115

    Question Store some addresses of variable to integer variable

    I want to save address of the pointer point to to my variable:
    So, I do that:
    Code:
     
    <Pointer>*a;
    int tmp=*a; //hope that tmp will store address that pointer a point to
    but the complier will give me an error:error: invalid conversion from 'Pointer**' to 'int.
    So, how can I do that, please help me, please.

    thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,592
    Why do you want to do this?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115
    Ah, I have a complete binary tree building by linked List. and of course, go to some node more difficult than if use array. and I want to convert this tree to array. (mean array[1]=address of first node, array[2]=address of second node, array[3]=address of third node,....). after that, I just use:
    Code:
    <pointer>*tmp=&array[i];
    And, don't ask me, why I don't use array instead of linked list zz

    thanks
    Last edited by hqt; 09-04-2011 at 11:39 AM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,592
    Quote Originally Posted by hqt
    Ah, I have a complete binary tree building by linked List. and of course, go to some node more difficult than if use array. and I want to convert this tree to array. (mean array[1]=address of first node, array[2]=address of second node, array[3]=address of third node,....).
    Create an array of pointers to the elements of the tree. Traverse over the tree and populate the array.

    Quote Originally Posted by hqt
    And, don't ask me, why I don't use array instead of linked list zz
    Why don't you use an array instead of a linked list?

    (Generally, I would not regard a tree as a linked list, though links are involved.)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    48
    You want a pointer to a pointer?

    Code:
    int* p		= new int;
    int** pp	= &p;
    Then pp contains the address of the pointer p.

    You can even do this, though I'm not sure why you would:

    Code:
    int add		= (int)&p;

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,537
    It should be noted that
    int add = (int)&p;
    may result in truncation since the size of an int is not necessarily the size of a pointer (64-bit windows is a prime example).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115
    Ah, array of pointer, I almost forget it :">
    And yes, of course when building tree, array is more suitable than linked list in most case. But linked list is "natural", and some applications may be use linked list is absolutely compulsory (example fibbonaci Heap)

    thanks
    Last edited by hqt; 09-04-2011 at 09:23 PM.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,592
    What I meant was that the concept of a tree and the concept of a linked list are distinct. A tree generally would have some kind of branching (even if it effectively just a linked list in special cases) whereas a linked list is a linear sequence. That you could use an array to implement some kinds of tree structures and use links to nodes to implement other tree structures is a separate matter.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Store pointee to an int variable
    By limp in forum C Programming
    Replies: 7
    Last Post: 05-25-2011, 03:17 PM
  2. Extract values and store in new variable
    By cosmiccomputing in forum C Programming
    Replies: 3
    Last Post: 06-01-2008, 01:45 PM
  3. which variable can store words?
    By Hunterofman in forum C++ Programming
    Replies: 8
    Last Post: 04-28-2008, 05:59 PM
  4. variable addresses and pointers
    By tzpb8 in forum C Programming
    Replies: 47
    Last Post: 07-26-2006, 07:08 PM
  5. store date in a variable
    By actionbasti in forum C++ Programming
    Replies: 2
    Last Post: 10-01-2003, 09:50 PM

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