Relationship between Pointers and Arrays in C
- Array name is a pointer to itself
- ANSI standard makes &a = a
- int x[10], *p = x; makes p = &x[0]
- while ( p < &x[4]) { sum+=*p; p++ }
- The compiler allocates contiguous space for all the elements row-wise in multidimensional arrays
- int x[10][20] and int *p = x is allowed
- When we increment i by 1, p will be incremented by the size of the row and not the size of the element itself
- p is pointer to first row, p+i is pointer to ith row, *(p+i) is the first element of the ith row
- *(p+i) + j is jth element of ith row
- *(*(p+i)+j) value stored in cell (i,j)
No comments:
Post a Comment