[prev] [index] [next]

Array Initialisation

Arrays can be initialised by code (as in previous example).

Alternatively, can specify an initial set of values in declaration.

Examples:

int v[8]  = {1, 2, 4, 8, 16, 32, 64, 128};

char s[4] = {'a', 'b', 'c', '\0'};

int w[]   = {5, 4, 3, 2, 1};

In the last case, C infers the array length   (as if we declared w[5]).