Relationship Between Arrays and Pointers

In C language, arrays and pointers are so closely related that they cannot be studied in isolation. They are often used interchangeably. The following relationships exist between arrays and pointers:
  1. The name of an array refers to the address of the first element of the array, i.e. an expression of array type decomposes to pointer type. Program 12 illustrates this fact.

    Program 12. A program to depict the relationship between arrays and pointers
    The name of an array refers to the address of the first element of the array but there are two exceptions to this rule:
    1. When an array name is operand of sizeof operator it does not decompose to the address of its first element. Program 13 illustrates this fact.


      Program 13. A program to illustrate the application of the sizeof operator on arrays
    2. When an array name is an operand of reference or address-of operator it does not decompose to the address of its first element.

  2. In C language, any operation that involves array subscripting is done by using pointers. The expression of form E1[E2] is automatically converted into an equivalent expression of form *(E1+E2). Program 14 illustrates this fact.


    Program 14. A program to depict the relationship between arrays and pointers

Post a Comment

Previous Post Next Post