In the absence of explicit initialisation, external and static variables are initialised to zero; automatic and register variables have undefined (garbage) initial values.
For external and static variables, the initialiser must be a constant expression; the initialisation is done once before the program begins execution.
int x = 1;
For automatic and register variables, the initialiser may be any expression involving previously defined values, even function calls.
int main() { int x = 2; int y = x * 10; int z = sqrt(y); ... }
An array may be initialised by following its declaration with a list of initialisers enclosed in curly braces and separated by commas.
int arr[] = { 10, 20, 30, 40, 50 };
When the size of the array is omitted, the compiler will compute the length by counting the initialisers (5 in the above example).
In cases where there are fewer initialisers than the array size:
int arr[5] = { 1, 2, 3 };
the missing elements will be zero for external, static and automatic variables. It is an error to have too many initialisers.
Character arrays can be initialised using strings instead of curly braces and comma notation:
char name[] = "foo";
is equivalent to
char name[] = { 'f', 'o', 'o', '\0' };
In both the cases, array is of size four (three characters plus the null character ‘\0’).