Menu

Assigning pointers to arrays.

Anonymous
2002-05-14
2012-09-26
  • Anonymous

    Anonymous - 2002-05-14

    Hi,

    How do I assign a pointer to an array?
    The following code doesn't compile...

    int myarr[8][8];
    /*
    ... here i'm filling the array
    */
    int *ptrarr;
    ptrarr = myarr;

    I tried to use the usual form for non-arrays (ptrarr=&myarr) but it also doesn't work... I'm at loss here.

    Mario

     
    • Anonymous

      Anonymous - 2002-05-16

      I am having similiar problems with arrays of pointers to pointers (I have posted in programming forum about it) Though i think i can help with the fundementals (I think:)
      Since you are using a two dimensional array, you cannot assign a double indirected pointer to a single indirected pointer. In other words, your multi-dimensional array is actually two sets pointers wrapped up into one, its an array of pointers to pointers. So in order to assign the Addresses of your multi-dimensional array into another, you have to double indirect it.
      Like this:

      int** ptrarr;
      ptrarr = myarr;

      Its confusing as hell, YES.
      I am still trying to get it. . . So dont be angry if i am wrong:)

      Good Luck, Sir
      Chris Brandt

       
    • Anonymous

      Anonymous - 2002-05-16

      How could I be angry when someone tries to help me :)

      Thanks Chris. :)

      Mario

       
    • Anonymous

      Anonymous - 2002-07-10

      Hi Mario

      This is how it's done:

      int myarr[8][8];
      /*
      ... here i'm filling the array
      */
      int *ptrarr;
      ptrarr = &myarr[0][0]; // note this line!

      I hope this helps!

      Dave Carter

      PS - Give me a shout if you want some more explanation.

       
    • Anonymous

      Anonymous - 2002-11-03

      You can find programs in C whith this subjet, but... in Spanish languaje.
      They are in "Arrays" folder in the URL:

      www.geocities.com/ismaelcamarero

      I've also a tutorial about "Pointers " in Tutoriales (PowerPoint file)

      Good Luck!

       
    • Troy Scheffel

      Troy Scheffel - 2002-11-12

      Try posting on comp.lang.c++ or comp.lang.c++.moderated newsgroups.  You'll receive answers from professional C++ developers.  I've learned a lot browsing those newsgroups.

       
    • Troy Scheffel

      Troy Scheffel - 2002-11-12

      Try posting on comp.lang.c++ or comp.lang.c++.moderated newsgroups.  You'll receive answers from professional C++ developers.  I've learned a lot browsing those newsgroups.

       

Log in to post a comment.

MongoDB Logo MongoDB