- Arrays may be initialised by following the definition with
a list of initialisers enclosed in {} separated by
commas.
int TopTen[10] = {0,1,2,3,4,5,6,7,8,9};
- Character arrays may also be initialised with character
strings. This adds a null at the end if the string is
shorter than the array.
char Name[32] = "Geoff Sutcliffe";
- If there are less initialisers than elements the extra
elements are initialised with 0 if external or
static, garbage if automatic. For example
int Data[10] = {};
initialises the entire array to 0/garbage.
- There may not be more initialisers than array elements.
- In the definition of an array the size may be implied by
the initialisation list. e.g.
int Data[] = {1,2,3,4,5,6};
defines an array of size 6 and
char Error[] = "Error\n";
defines an array of size 7.