Arrays or One Dimentional Arrays: Definition
Arrays or One Dimentional Arrays: Definition
Definition: Array is a collection of similar elements of same data type such as int, float, char , etc. Explanation: To store more than one value at a time in a single variable. This
Syntax:
datatype subscripted_variable[arraysize];
Example :
n is name of variable
[] tells compiler dealing with array 6 tells how many elements in array . This is called dimension of
array
Dimension of array is optional. This mentioned in 2nd example. There is no value in subscript.
Storage structure
n[5] n[4] n[3] n[2] n[1]
6 5 4
3 2
1
2004
2002
n[0]
2000
Example :
main() { int n[5][2] = {
int i , j ;
} ;
{ { { { {
1 2 3 4 5
, , , , ,
2 5 4 5 6
} } } } }
, , , ,
0th 1-D
1st 1-D
2nd 1-D
3rd 1-D
4th 1-D
4000
4002
4004
4006
4008
4010
4012
4014
4016
4018
int n[5][2] contains 5 one dimentional array . Each one dimentional array contains 2
values
n[i][j] 1 st subscript is row no 2 nd subscript is column no
Definition:
It is a collection of number of 2-D arrays placed one after
another . It is also called as array of array.
Example
main() { int n[2][2][2] = { { {1,2} , {2,3} } , { {3,4}. {4,5} } }; Int I,j,k; For(i=0;i<=1;i++) { for(j=0;j<=1;j++) { for(k=0;k<=1;k++)
printf( %d , n[i]i[j][k]) ;
} }
0th 2-D
1st 2-D
0th 1-D
1st 1-D
0th 1-D
1st 1-D
4000
4002
4004
4006
4008
4010
4012
4014
int n[2][2][2] contains two 2-D array . Each 2-D array contains 2 1-D array Each 1-D array contains two elements
n[i][j][k]
I 2-D array j 1-D array or row k element or column
n[0][0][0] n[0][0][1]
n[0][1][0] n[0][1][1] 2 3
Quiz
5.
main()
{ Int size; Int arr[size]; Scanf(%d,&size); for(i=0;i<=size;i++) { Scanf(%d,arr[i]); Printf(%d,arr[i]); } }