2d arrays

This is a discussion on 2d arrays within the C Programming forums, part of the General Programming Boards category; Ok, so lets say we have int foo[10][20]; What exactly is foo itself? Is it a pointer to pointer? If ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272

    2d arrays

    Ok, so lets say we have

    int foo[10][20];

    What exactly is foo itself? Is it a pointer to pointer?

    If so, i tried declaring a pointer to pointer and make it point to foo, but that didnt work.

    Then i tried int (*foop)[10][20];

    but im confused on how to get that pointer to point to the pointer to second row.

    could someone give me some info about how pointers and 2d arrays work?
    Last edited by Tool; 04-15-2010 at 09:21 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,733
    Quote Originally Posted by Tool
    What exactly is foo itself? Is it a pointer to pointer?
    No, it is an array of 10 arrays of 20 ints.

    Quote Originally Posted by Tool
    could someone give me some info about how pointers and 2d arrays work?
    Like any other array, foo is converted to a pointer to its first element. Since its first element is an array of 20 ints, it is converted to an int (*)[20], e.g.,
    Code:
    int (*p)[20] = foo;
    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. Passing 2D arrays between functions
    By taurus in forum C Programming
    Replies: 10
    Last Post: 09-28-2009, 05:05 AM
  2. Help with 2d arrays
    By thamiz in forum C Programming
    Replies: 25
    Last Post: 05-25-2008, 05:06 AM
  3. returning 2D arrays
    By ... in forum C++ Programming
    Replies: 2
    Last Post: 09-02-2003, 12:28 PM
  4. Initialising 2D and 3D arrays
    By fry in forum C++ Programming
    Replies: 5
    Last Post: 08-01-2002, 04:34 AM
  5. Reading 2d arrays from file?
    By Ringhawk in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2002, 08:05 PM

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