An array is a collection of elements of the same type at consecutive memory locations. The lowest address corresponds to the first element, and the highest address corresponds to the last element.
Array indexing starts with zero (0) and ends with the array size minus one (array size - 1). Array size must be an integer greater than zero.
Let us look at an example,
If array size = 10 First index of array = 0 Last index of array = array size - 1 = 10-1 = 9
This is the syntax of an array in C language,
type array_name[array_size ];
The following is the method of initializing an array.
type array_name[array_size] = { elements of array }
This is an example of C language array,
Live demonstration
#include <stdio.h> int main () { int a[5]; int i,j; for (i=0;i<5;i++) { a[i] = i+100; } for (j=0;j<5;j++) { printf("Element[%d] = %d</p><p>", j, a[j] ); } return 0; }
Element[0] = 100 Element[1] = 101 Element[2] = 102 Element[3] = 103 Element[4] = 104
The above is the detailed content of Array in C language. For more information, please follow other related articles on the PHP Chinese website!