Int array and its pointer : Array Int « Data Type « C / ANSI-C






Int array and its pointer

  
#include <stdio.h>

int main(void)
{
  int a[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
  int *p;

  p = a; /* assign p the address of start of array a */

  /* output a's first, second and third elements using pointer */
  printf("%d %d %d\n", *p, *(p+1), *(p+2));

  /* this does the same thing using a */
  printf("%d %d %d", a[0], a[1], a[2]);

  return 0;
}


           
       








Related examples in the same category

1.Prints out numbers and their doubles
2.Shows two ways an array can be cleared
3.An example of how to initialize a matrix: loop
4.Array initializationArray initialization
5.Define array and use it
6.Assign int value reference to int arrayAssign int value reference to int array
7.Array: assign and retrieve valueArray: assign and retrieve value
8.Output array addressOutput array address
9.Allocate memory for int arrayAllocate memory for int array
10.Declares a 100-integer array
11.Reference element in array
12.an example of using an array for two tasks
13.Use for loop to calculate the square and save it to array
14.Define int array and assign value
15.how to use arrays with functions