Declaration of One-Dimensional Arrays:
Like
any other variable, arrays must be declared before they are used so that the
compiler can allocate space for them in memory. The general form of array
declaration is
The type specifies the type of element that
will be contained in the array, such as int, float, or char and the size
indicates the maximum number of elements that can be store inside the array.
For Example
int a[ 5 ];
declares
the a to be an array containing 5 integer elements. Any subscripts 0 t0 4 are
valid.
Note
that:
1.
Any reference to the arrays outside the declared limits would
not necessarily cause an error. Rather, it might result in unpredictable
program results.
2.
The size should be either a numeric constant or a symbolic
constant.
The
C language treats character strings simply as arrays of characters. The size in
a character string represents the maximum number of characters that the string
can hold. For instance,
char name[10];
declares
the name as a character array (string) variable that can hold a maximum of 10
characters. Suppose we read the following string constant into the string
variable name.
“WELL DONE”
Post a Comment