# include int main ( ) { int a[3] = { 10, 20, 30 }; int b[3] = { 40, 50, 60 }; int c[3] = { 70, 80, 90 }; int i; int value; int *vp; // // The name of an array is a pointer. // If we want VP to point to A, we can simply use an "=" statement. // vp = a; printf ( " The value of A, which is a pointer, is %p\n", a ); printf ( " The value of VP, which is a pointer currently pointing to A, is %p\n", vp ); printf ( "\n" ); printf ( " The first entry in A is A[0] = %i\n", a[0] ); printf ( " The third entry in A is A[2] = %i\n", a[2] ); printf ( "\n" ); printf ( " The first entry in A is also *VP = %i\n", *vp ); printf ( " The third entry in A is also *(VP+2) = %i\n", *(vp+2) ); printf ( "\n" ); printf ( " We are not allowed to change A, it always points to the array A.\n" ); printf ( " But we CAN change VP.\n" ); printf ( "\n" ); vp = vp + 1; printf ( " After \"vp=vp+1\", we have *VP = %i\n", *vp ); vp = vp + 1; printf ( " After \"vp=vp+1\", we have *VP = %i\n", *vp ); printf ( "\n" ); printf ( " Now, move VP to point to the B array.\n" ); vp = b; printf ( " After \"vp = b\", we have *VP = %i\n", *vp ); printf ( " Now use VP to change and print entries in B\n" ); *vp = *vp + 1; printf ( " After \"*vp = *vp + 1\", we have *VP = %i\n", *vp ); printf ( " If we add 1 to vp, we move to the next entry in B:\n" ); vp = vp + 1; printf ( " After \"vp=vp+1\", we have *VP = %i\n", *vp ); printf ( "\n" ); printf ( " To sum the elements of C, we can use a loop that increments vp\n" ); value = 0; vp = c; for ( i = 0; i < 3; i++ ) { value = value + *vp; vp = vp + 1; } printf ( " We get a sum of %d\n", value ); return 0; }