An Array is user define data type. It is collection of several elements of similar data type, where we can store multiple values at a time.
Syntax:
Data Type ArrayName [ No_of_element ];
e.g.
int Arr[5]
Properties of Array:-
1. All elements exist on continues memory locations.
Here i am assuming that it starts from location 100 in memory.int A[5];
2.Each element is identified by a number, which called as index no. The index no begins from 0 to N-1.
int A[5];
Here N = 5
0 1 2 3 4
3.All elements of an array are of same type.
int A[5];
float A[5];
long A[5];
4.Length of array must defined by a constant integer.
int A[5]; = OK
float A[5]; = OK
int A[]; = error
int A[5.7]; = error
int A[l]; = error
int A[l*2]; = error
5.The size of array is sum of size of its elements.
int a[5]; SIZE = 10
float a[200]; SIZE = 800
long a[44]; SIZE = 132
6.All elements of array are automatically initialized by garbaze.
7.Initialization of array:
int a[5] = {10,20,30,40,50};
0 1 2 3 4
| 10 | 20 | 30 | 40 | 50 |
Partial Initialization-
int a[5] = {10,20,30};
0 1 2 3 4
| 10 | 20 | 30 | 0 | 0 |
int a[100] = {0};
0………………………………………………………………………………………………………………………………………….99
| 0 | 0 | 0 | 0 | 0 |
int a[] = {10,20,30,40,50};
| 10 | 20 | 30 | 40 | 50 |
8.The size of an array also defined by a symbolic constant/macro.
#define sz 25
double A[sz];
int B[sz];
char C[sz];