Presentation is loading. Please wait.

Presentation is loading. Please wait.

Array Array Array Dimension 3. One dinensional array

Similar presentations


Presentation on theme: "Array Array Array Dimension 3. One dinensional array"— Presentation transcript:

1 Array Array Array Dimension 3. One dinensional array
Two dimensional array Multi dimensional array Advantages and limitations of Array

2 Array An array is a fixed size sequenced collection of elements of the same data type. An array can be used to represent a list of number, or a list of names.

3 Array Dimension An array’s dimension is the number of indices required to reference on eiement. Types of arrays : One dimensional arrays. Two dimensional arrays. Multi dimensional arrays.

4 1.One dimensional array A list of items can be given one variable name using only one subscript and such a variable is called a one dimensional array. A general form of array declaration is datatype arrayname[size]; Example int a[10];

5 Compile time initialization
The general form of array initialization is type arrayname[size] = { list of values Example When the size of an array is omitted , thattime the compiler allocates enough space for all initialized element. int a =[123] har name[] ={‘h’E’,’l’,l’O’\0’} run time initialized

6 Run time initialization
for(i=0:i++) { Scanf(”%d”,&sum [i]); } Representation of a one dimensional arry in memory if Int a[5]={1,2,3,4,5,}; Then the array in memory will be stored like: a[0]=1 a[1]=2 a[2]=3 a[3]=4 a[4]=5

7 Two Dimensional array Two Dimenisonal array are declared as follows:
Type arrayname [row_size] [column_size]; Example: int table [2][3]={0,0,0,1,1,1}; or for (i=0;<2i;++) { For (i=0;<3;j++) scanf(‘’%d’ , &table [i][i]); }

8 Multi-dimensional Arrays
the general from of a multi- dimensional array is type arrayname [s1][s3]……….[sn] example int spacepoint[3][5][2]; Flot table [5][4][5][3];

9 Advantages of array There are many reasons why a programmer might whant to use on array in a program One motivation for using on array is the reduction of identifiers array are a convenient why of grouping a lot of variables under a single variable name Array are most useful when they have a larage number of elementss: that is in cases where it whould be completeley impractical to have a different name for every stroage spce in the memory . It is then highaly beneficial to move over to array for storing information fot two reasons:the storage space in arrays have indices. Usinge indicese it is easy to process group loop constructs

10 Limitation of arrays Because a name of arrays represent just a pointer to the beginning of the array, we have some limitations or”problems.’’ (1) no array out of bounds checking. For example: int a [2]={0,1,}; Printf(%d’, a [2]; The above code whould generate error because you are trying to look at on area of memory not inside the array memory allocation.

11 (2) Array size must be constant or known at compile-time.
(3) Arrays can not be copied or compered because they are pointers. (4)Array index type must be integral.

12 THANK YOU


Download ppt "Array Array Array Dimension 3. One dinensional array"

Similar presentations


Ads by Google