/*------------------------------------------------------------------*/ /* revp2.c */ /* Author: Bob Dondero */ /* The relationship between arrays and pointers. */ /*------------------------------------------------------------------*/ #include enum {ARRAYSIZE = 5}; int main(void) /* Read ARRAYSIZE integers from stdin, and write them in reverse order to stdout. Return 0. */ { int aiNumbers[ARRAYSIZE]; int* piCurrent; int* piAfterLast; piAfterLast = aiNumbers + ARRAYSIZE; printf("Enter %d integers:\n", ARRAYSIZE); piCurrent = aiNumbers; while (piCurrent != piAfterLast) /* Could use "for" statement. */ { scanf("%d", piCurrent); piCurrent++; } printf("\n"); printf("The integers in reverse order are:\n"); while (piCurrent != aiNumbers) { piCurrent--; printf("%d\n", *piCurrent); } return 0; }