Generating a Pointer to an Array


You can generate a pointer to the first element of an array by simply specifying the array name, without any index, For example, given

int numbers[10];

Using the numbers array, you can create a pointer to the first element. Thus, the segment of the following program assigns the address a to the first element of the number:

int numbers[10];
int *a;
a = numbers;

You can also specify the address of the first element of an array using the & operator. For example, numbers and &numbers[0] both produce the same results. However, in professionally written C code, you will rarely see &numbers[0].

Sample Program

Program
#include <stdio.h>

int main() {
  int a[10]; /* this declares a 10-integer array */
  int i;
  int *p;
  
  for(int i=0; i<10; i++)
  {
   a[i] = i;
  }
  p = &a[1];
  int v = *p;
  printf("%d",v);
  return 0;
}