Initilization of Array : assigning the required information to a variable before processing is called
initialization.we can initialize the individual elements of an array. Array elements can be initialized at the time
of declaration.
Syntax : data_type array_name[size]={v1,v2,…vn};
Where
- data_type : can be a basic data type such as int,float , char etc.
- array_name : is the name of the array.
- Size : size should be evaluated to a positive integer only. It can also be an integer constants.
- v1,v2,..vn are the values and should be enclosed within ‘{‘ and ‘}’ separated by commas. The value v1
is assigned to the 0th location, v2 is assigned to 1st location and so on.
Ex:
int a[5]={10,20,30,40,50};
char b[8] = {‘C’,’O’,’M’,’P’,’U’,’T’,’E’,’R’};
int a[5]={10,15};
char b[]={‘C’,’O’,’M’,’P’,’U’,’T’,’E’,’R’};
char b[] = “COMPUTER”;