Understanding c-pointers for rows in 2-dimensional array

Posted by utdiscant on Stack Overflow See other posts from Stack Overflow or by utdiscant
Published on 2010-04-19T21:24:01Z Indexed on 2010/04/19 21:43 UTC
Read the original article Hit count: 200

I have the following code:

int main() {
    int n = 3, m = 4, a[n][m], i, j, (* p)[m] = a;
    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            a[i][j] = 1;
    p++;
    (*p)[2] = 9;
    return 0;
}

I have a hard time understanding what p is here, and the consequences of the operations on p in the end. Can someone give me a brief explanation of what happens. I know c-pointers in their simple settings, but here it get slightly more complicated.

© Stack Overflow or respective owner

Related posts about c

    Related posts about array