You are on page 1of 1

Note & Programs on ARRAY

Definition of array? An array is an ordered sequence of finite data items of the same data type and of the same storage class that share a common name. The common name is known as array name and each individual data item is called array element (or element of the array). How do we refer an array element? Each array element is referred to by specifying the array name followed by one or more subcripts, with each subscript enclosed in square brackets. For example, A[1], A[2] represent array elements of an array having array name A. Similarly, B[2][1] represents an array element of an array having array name B. Dimension of an array: The number of subscripts determines the dimensionality of the array. When the number of subscript is one, the array is called one-dimensional array (single-subscripted variable). When the number of subscripts is two, the array is called two-dimensional array. When the number of subscripts is more than two, the array is called multi-dimensional array.
Declaration of an array:

int marks[5]; int marks[5] = {10, 56, 89, 65, 23}; int marks[] = {10, 56, 89, 65, 23}; Here, in each case, size of array(array size) is 5. Note on arrays in C: a) The array elements are always stored in consecutive memory cells/locations. b) The index of the first element in an array is always zero. c) The number of elements in an array must be a constant. For example, you cannot do this : int n; scanf(%d,&n);int arr[n];

Compiled by Alok Basu for 2nd SEM CSE students of SIT

You might also like