Page 9 - Sample_test_Float
P. 9

Functions and Pointers  9


              5.2.8. Pointer and Array
              An array and pointer go hand in hand with each other. An array can be accessed by using pointer. Arrays
              and pointers are synonymous in terms of how they use to access memory. But the important difference
              between them is that a pointer variable can take different addresses as value, whereas in case of array it is
              fixed.

              Relation between Arrays and Pointers
              Array elements are stored in consecutive memory location.



               Example 1

               Consider and array:
               int arr[4];

                                             arr
                                                     arr[0] arr[1] arr[2] arr[3]




                                                      Figure: Array as Pointer



              In arrays of C programming, name of the array always points to the first element of an array. Here, address of
              first element of an array is &arr[0].arr represents the address of the pointer where it is pointing. Hence, &arr[0]
              is equivalent to arr.
              The statement
                                                      int arr[1]={10};
              is

              equivalent to
                                                        int *arr;
                                                        arr[0]=10;
                                                        arr = &a[0];

              Similarly,
                                   &a[1] is equivalent to (a+1)AND, a[1] is equivalent to *(a+1).
                                   &a[2] is equivalent to (a+2)AND, a[2] is equivalent to *(a+2).

                                   &a[3] is equivalent to (a+1)AND, a[3] is equivalent to *(a+3).
                                   &a[i] is equivalent to (a+i) AND, a[i] is equivalent to *(a+i).

              In C, you can declare an array and can use pointer to access the elements of an array
   4   5   6   7   8   9   10   11   12   13   14