Home » Blog » What is the difference between array and pointer?

What is the difference between array and pointer?

Pointers are used for storing address of dynamically allocated arrays and for arrays which are passed as arguments to functions. In other contexts, arrays and pointer are two different things.

 

  1. Array name gives address of first element of array.
  2. Array members are accessed using pointer arithmetic.
    Compiler uses pointer arithmetic to access array element. For example, an expression like “arr[i]” is treated as *(arr + i) by the compiler. That is why the expressions like *(arr + i) work for array arr, and expressions like ptr[i] also work for pointer ptr.
  3. Array parameters are always passed as pointers, even when we use square brackets

Leave a Reply

Your email address will not be published.