Syntax:
storage_class data_type
array_name[expression];
Where, storage_class refers to the
storage class of the array. It may be auto,
static, extern. But it is
optional.
data_type is the data type of
array. It may be int, float, char, ….etc. If int is
used, this means that
this array stores data items of integer types.
array_name is name of the
array. It is user defined name for array.
[] represents the array and expression
inside this may be integer constant like
10, 100 or Symbolic constant
like SIZE (i.e. #define SIZE 80, this can be
used as int a[size];). This
expression represents the number of elements in
array.
Example:
int a [5];
It tells to the compiler
that ‘a’ is an integer type of array and can store 5 integers. The compiler
reserves 2 bytes of memory for each integer array element.
It’s individual elements are recognized by a[0], a[1],a[2],a[3] and a[4].
The integer value inside [] is called index of array. Index always starts from
0 and ends with one less than size of array.
Similarly, long num[5]; char ch[10]; are another
examples of array declarations
Comments
Post a Comment