/* CpSc 215 Example: Illustrate pointer basics */ /* ** This program illustrates some introductory concepts of ** pointers in C. */ #include #include int main(void) { int n = 10; int *p; int a[5]; int i; /* Initialize a to {0, 2, 4, 6, 8}. */ for (i=0; i<5; i++) a[i] = 2*i; p = &n; printf("\np is %d, *p is %d, n is %d\n", p, *p, n); *p = *p + 7; printf("\nAfter *p += 7, n is %d\n", n); p = &a[0]; printf("\nStarting p at a[0] and incrementing:\n"); for (i=1; i<6; i++) { printf(" %d", *p); p++; } printf("\n"); printf("\nChecking the elements of a:\n"); for (i=0; i<5; i++) printf(" %d", a[i]); printf("\n"); return EXIT_SUCCESS; }