One Dimensional Array
| What is Array? | |||||||||||
| Array
is a collection of variables of same data type. Array is used to store more
then one
values of same data type under common name. All the variables in an array share one common
name. |
|||||||||||
| Types of Array | |||||||||||
| There are three
types of array |
|||||||||||
| One Dimensional Array | |||||||||||
| One Dimensional
Array can be represented using only one subscript. Syntax
DataType ArrayName[Size]; Here, Size indicates number of values that can be stored in an array. Example int a[5]; Here, a is an array that can store 5 values of type integer. Individual
element of an array can be identify using an array name along with index. Index
in an array always starts with 0. So First element is a[0], second is a[1] and so
on.
Ammount of
memory occupied by an array can be calculated using equation: Syntax
DataType ArrayName[Size]= {value1,value2,...valueN}; Example int a[3]={1,2,3}; If number
of values specified in curly bracket is less then the number of elements in an array
then remaining elements are initialized with 0. Example int i,a[10]; for(i=0;i<10;i++) { printf("Enter Value:"); scanf("%d",&a[i]); } |
|||||||||||