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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ Problem

  • 25-03-2006 11:29am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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