C - Language: Arrays (I)
C - Language: Arrays (I)
Arrays (I)
Why, when, what….
It Arrays
becomes more difficult to keep track of n-number of
variables in a program. Arrays offer a solution to this
problem.
An array is a multi-element box, a bit like a filing cabinet,
and uses an indexing system to find each variable stored
within it. In C, indexing starts at zero.
Arrays, like other variables in C, must be declared before
they can be used.
Arrays may consist of any of the valid data types.
Arrays are declared along with all other variables in the
declaration section of the program.
Arrays
A group of related data items that share a common
name.
Can be of any variable type.
Is a data structure that holds multiple variables of the
same data type.
Individual elements in a array are indicated by the index
number or subscript in brackets after the array name
Usage
Or
10 value[0]
value[3] = 25; 20 value[1]
30 value[2]
printf(“%d”, value[3]); 40 value[3]
50 value[4]
Initialization of Arrays
General form :-
type array-name [size] = { list of values }
Drawbacks:-
There is no convenient way to initialize only selected
elements.
characters.
Usage :-
Usage :-
if(name1 == name2)
` NOT POSSBILE
if(name == “NSBM”)