Thread: array of pointers each pointing to an array

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    129

    array of pointers each pointing to an array

    Ive created an array of pointers that each points to the beginning of different arrays but I need to know how to access the elements inside each of the arrays they point to.

    I got something kinda like this but a bit more complex
    [code]
    int *CowPointer[64];
    int whatever[32];

    CowPointer[0]=&whatever;
    [/cow]

    now how do I access the individual elements in whatever, I kinda doubt I can say CowPointer[0][5] to access whatever[5], but I donna, Im not at home to try.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    int *CowPointer[64]; 
    int whatever[32]; 
    CowPointer[0]=whatever;
    Then
    CowPointer[0][x] is the same as whatever[x]

  3. #3
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70
    is't obvious that it will behave and be accessed as a two dimetional array.
    Ünicode¬>world = 10.0£

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    129
    but when I try to access it as a 2 dimensional array it complains about something (Im not at home so I forget what).
    flashdaddee.com rocks!!!

  5. #5
    Unregistered
    Guest
    Alright I compiled this at school, heres a perfect example of the problem:

    Code:
    #include <stdio.h>
    
    int main()
    {
       int *BigDumbPointer[50]; //array of pointers
       int test[32]; //array of ints
    
       BigDumbPointer[0]=test; //assign address of test to pointer
    
       *BigDumbPointer[0][0]=1; //just to show that it ..........s up
       
    
       return 0;
    }
    the error is:
    Invalid indirection
    and its on the line that I show it messes up on.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Loose the asterisk, as in
    Code:
    BigDumbPointer[0][0]=1; //just to show that it won't .......... up
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    129
    Oops, sorry that makes sense.
    flashdaddee.com rocks!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to sort an array of pointers to structure
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 06-30-2008, 02:52 PM
  2. Syntax for constant array of array pointers
    By BMintern in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 08:21 AM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. array of pointers to struct array
    By eth0 in forum C++ Programming
    Replies: 1
    Last Post: 01-08-2004, 06:43 PM
  5. array of pointers to structs
    By stumon in forum C Programming
    Replies: 7
    Last Post: 03-24-2003, 07:13 AM