We have reserved 100 integer memory locations for our matrix, A.
This is 100*2 bytes (for ANSI C integers).
Assume that this is reserved as contiguous memory starting at hex
address fed0H. The data will be stored by rows.
// A rose is a rose by any other name // A value is a value by any other address style #include#include main() { // int A[2][3]; /* The storage map for this 2 dimensional array or matrix is A[0][0] A[0][1] A[0][2] A[1][0] A[1][1] A[1][2] That is C/C++ stores a matrix linearly in rows. The values for the matrix elements are referenced as A[i][j] = (*(A+i))[j] = *((*(A+i))+j) = *(A[i]+j) The adresses for the matrix elements are &A[i][j] = (A+i)[j] = (*(A+i))+j = A[i]+j */ // I want to initialize the matrix when I declare it int A[2][3] = { {1, 2, 3}, {4, 5, 6} }; // several ways to get the values // C output printf("\nThe value of element A[0][0] is \n"); printf("%d %d %d %d \n", A[0][0],(*(A+0))[0],*((*A)+0),*(A[0]+0) ); // C++ output cout << "The value of element A[0][0] is \n" << A[0][0] << " " << (*(A))[0] << " " << *((*A)+0) << " " << *(A[0]+0) << "\n"; cout << "The value of element A[0][2] is \n" << A[0][2] << " " << (*(A))[2] << " " << *((*A)+2) << " " << *(A[0]+2) << "\n"; cout << "The value of element A[1][2] is \n" << A[1][2] << " " << (*(A+1))[2] << " " << *((*(A+1))+2) << " " << *(A[1]+2) << "\n"; // several ways to address the elements // C output printf("\nThe address of element A[0][0] is \n"); printf("%0x %0x %0x %0x\n",&A[0][0],(A)[0],(*A+0),(A[0]+0)); // C++ output cout << "The address of element A[0][0] is \n" << &A[0][0] << " " << &(*(A))[0] << " " << *(A)+0 << " " << A[0]+0 << "\n"; cout << "The address of element A[0][2] is \n" << &A[0][2] << " " << &(*(A))[2] << " " << *(A)+2 << " " << A[0]+2 << "\n"; cout << "The address of element A[1][2] is \n" << &A[1][2] << " " << &(*(A+1))[2] << " " << *(A+1)+2 << " " << A[1]+2 << "\n"; // Notice how these addresses work cout << "\nNotice what points to where \n"; cout << &A[0][0]+1 << " " << A[0]+1 << " " << A+1 << " " << &A[0]+1; cout << "\n interesting? \n"; return(0); }