Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ Problem

Options
  • 25-03-2006 12:29pm
    #1
    Registered Users Posts: 871 ✭✭✭


    Hey, I'm just wondering how do you pass a value from an integer to an address in an array pointer, (also int)

    Any help would be greatly appreciated. Thanks
    Ger...


Comments

  • Closed Accounts Posts: 17,163 ✭✭✭✭Boston


    X= your integer value
    Y = your address

    *Y = X (the think Y points to is assigned the value X)

    That should be it from what I remember.

    Edit, I didn't read your post fully.

    So you have something like this

    typedef int* IntPtr

    IntPtr a;
    a = new IntPtr[size_of_block]

    //Now you have an array of pointers.
    //To assign an individual pointer, do like you would normally.

    *a[2] = x (where X is a value)


  • Registered Users Posts: 871 ✭✭✭gerTheGreat


    that's it thanks a mill
    ger...


  • Closed Accounts Posts: 60 ✭✭goldilocked


    This looks dodgey to me...

    You've created an array of size integer pointers.

    You're then storing the value x in the address contained in the second array entry. But you have not allocated this storage.


  • Closed Accounts Posts: 17,163 ✭✭✭✭Boston


    True, but the question was how to assign pointers in an array. The bit of code demonstates that, it doesn't demonstate how to set up a pointer array. Just include a for loop that assigns storage to each of your pointers in the array

    for(int i = 0; i<size;i++){
    a = new int;
    }


  • Closed Accounts Posts: 60 ✭✭goldilocked


    Well if the OP's learning how to program, they may aswell also learn our pedantic ways!


  • Advertisement
Advertisement