/* * =========================================================================== * prog_pointers6.c : Demonstrate use of array index and pointer notation for * accessing/printing elements of a two-dimensional matrix. * =========================================================================== * Copyright (C) 1993-96 by Mark Austin and David Mazzoni. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * =========================================================================== */ #include enum { NoRows = 4, NoCols = 2 }; int main ( void ) { int iaaTest[ NoRows ][ NoCols ] = {{ 1, 2}, { 3, 4}, /* declare and initialize */ { 5, 6}, { 7, 8}}; /* (4x2) array */ int ii, ij; /* integer counters */ int *ipPtrToInt; /* pointer of type int */ /* [a] : Use pointer notation to access and print array contents */ for (ii = 0 ; ii < NoRows; ii = ii + 1) { ipPtrToInt = *(iaaTest + ii); for (ij = 0 ; ij < NoCols; ij = ij + 1) { printf(" %4d", *(ipPtrToInt + ij )); } printf("\n"); } }