#include using namespace std; void foo1(int *fa, int fn) { for (int i = 0; i < fn; ++i) { cout << "fa[" << i << "]=" << fa[i] << " "; } cout << endl; for (int i = 0; i < fn; ++i) { cout << "*fa is " << *fa << " "; ++fa; } cout << endl; } void foo2(int *fa, int fr, int fc) { for (int i = 0; i < fr; ++i) { for (int j = 0; j < fc; ++j) { cout << "fa[" << i << "][" << j << "]=" << (fa+i*fc)[j] << " "; } cout << endl; } } void foo3(int fa[][4], int fr) { int fc = sizeof(fa[0])/sizeof(int); for (int i = 0; i < fr; ++i) { for (int j = 0; j < fc; ++j) { cout << "fa[" << i << "][" << j << "]=" << fa[i][j] << " "; } cout << endl; } } int main() { int a[][4] = { { 1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12} }; int nrows = sizeof(a)/sizeof(a[0]); int ncols = sizeof(a[0])/sizeof(int); cout << "nrows=" << nrows << ", ncols=" << ncols << endl; for (int i = 0; i < nrows; ++i) { for (int j = 0; j < ncols; ++j) { cout << "a[" << i << "][" << j << "]=" << a[i][j] << " "; } cout << endl; } cout << endl << "a is " << a << endl; for (int i = 0; i < nrows; ++i) { cout << "a[" << i << "] is " << a[i] << endl; for (int j = 0; j < ncols; ++j) { cout << "&a[" << i << "][" << j << "]=" << &a[i][j] << " "; } cout << endl; } cout << endl; foo1(&a[0][0], nrows*ncols); cout << endl; foo2(&a[0][0], nrows, ncols); cout << endl; foo3(a, nrows); return 0; } #if 0 for (int i = 0; i < nrows; ++i) { cout << "&a[" << i << "]=" << &a[i] << (i==nrows-1 ? "\n" : " "); } #endif