Sams Teach Yourself C in 21 Days

(singke) #1
53: int *p, count;
54: p = (int *)ptr;
55:
56: for (count = 0; count < (4 * n); count++)
57: printf(“\n%d”, *p++);
58: }

1 2 3 4 5 6 7 8 9

10
11
12
Press Enter...

1 2 3 4 5 6 7 8 9

10
11
12
On lines 11 through 13, the program declares and initializes an array of integers,
multi[3][4]. Lines 6 and 7 are the prototypes for the functions printarray_1()
andprintarray_2(), which print the contents of the array.
The function printarray_1()(lines 36 through 47) is passed only one argument, a
pointer to an array of four integers. This function prints all four elements of the array.
The first time main()callsprintarray_1()on line 27, it passes a pointer to the first ele-
ment (the first four-element integer array) in multi. It then calls the function two more
times, incrementing the pointer each time to point to the second, and then to the third
element of multi. After all three calls are made, the 12 integers in multiare displayed
on-screen.

396 Day 15

LISTING15.4 continued

OUTPUT

ANALYSIS

25 448201x-CH15 8/13/02 11:13 AM Page 396

Free download pdf