Passing pointer to double array to function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prkwl1
    New Member
    • Apr 2010
    • 1

    #1

    Passing pointer to double array to function

    Hi,

    I'm new to C and am really confused about how C handles pointers and double arrays. For instance, I'm trying to do something like the following:

    Code:
    typedef int matrix[100][100];
    typedef matrix *matrixpointer;
    Then I allocate memory

    Code:
    matrixpointer p = (matrixpointer)malloc(sizeof(int) * 100 * 100);
    And then try to pass it to a function, SetupMatrix:

    Code:
    SetupMatrix(p);
    Where SetupMatrix is defined as:

    Code:
    void SetupMatrix(matrixpointer p) {
         matrix m = *p;
         m[0][0] = 10;
         ....
         ....
         return;
    }
    However this doesn't seem to work. Does any one know what's going on? Thanks!
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    All your questions are answered here:

    Comment

    Working...