Arrays
An Array is a collection of elements of similar
datatypes which are stored in continuous memory location and referred by a
single name.
Arrays a kind of data structure that can store a fixed-size
sequential collection of elements of the same type.
Declaration of an
Array:-
datatype name [size];
·
Datatypes indicates the types of
elements which are clubbed together in the array.
·
Array name is name given to the group of
elements which are grouped together in the array.
Ex: -
int arr[5];
char ch[7];
Here, ‘arr’ is the name given to group
of 5 integer variables which are stored in the continuous memory location, and
‘ch’ is a name given to a group of character variables.
To access individual elements of an
array, array name followed by subscript is used.
array_name [subscript];
Subscript indicates the position of
elements in the array. In C language the position of 1st element in
array is assumed to be zero and the upper bound that is last element in group
is assumed to be size ‘-1’.
Ex:-
int arr[5];
Arrays in Detail
Arrays need to be given a lot more attention as
they are important in C. The following important concepts related to array
should be very clear to a C programmer −
Sr.No.
|
Concept & Description
|
1
|
C supports multidimensional arrays and the
simplest form of the multidimensional array is the two-dimensional array.
|
2
|
We can pass to the function a pointer to an array
by specifying the array's name without an index.
|
3
|
C allows a function to return an array.
|
4
|
We can generate a pointer to the first element of
an array by simply specifying the array name, without any index.
|
No comments:
Post a Comment