Arrays |
|
|
|||
You have already studied about arrays
and are well-versed with the techniques to utilize these data structures.
Here we will discuss how arrays can be used to solve computer problems.
Consider the following program: main( int argc, char**
argv ) { int x[6]; int j; for(j = 0; j < 6; j++) x[j] = 2 * j; } We have declared an int array of six elements and
initialized it in the loop. Let’s revise some of the array
concepts. The declaration of array is as int
x[6]; or float x[6]; or double x[6]; You have already done
these in your programming assignments. An array is collection of cells of the
same type. In the above program, we have array x of type int of six
elements. We can only store integers in this array. We cannot put int in first location, float in second location and double in third location. What is x? x
is a name of collection of items. Its individual items are numbered from zero
to one less than array size. To access a cell, use the array name and an
index as under: x[0], x[1], x[2], x[3], x[4], x[5] |
|||||
|
BACK |
HOME |
NEXT |
||