Array initialization

From: R (tinwhistle_at_poczta.onet.pl)
Date: 09/23/04


Date: Thu, 23 Sep 2004 11:26:06 +0200

K&R 2nd Edition
4.9
"If there are fewer initializers for an array than the specified size,
the others will be zero for external, static and automatic variables. It
is an error to have too many initializers. There is no way to specify
repetition of an initializer, nor to initialize an element in the middle
of an array without supplying all the preceding values as well."

1) int Arr1[5];
2) int Arr2[5] = { };
3) int Arr3[5] = {0};

My compiler is BC++ 5.5

1) Arr1 is initialized with zeros, but AFAIK it's compiler dependant,
isn't it?
2) Arr2 - this does not compile. I thought that it would initialize the
array with zeros, because there are fewer initializers for an array (in
this case none) than the specified size, the others (all) will be zero.
Does the standard disallow empty initializer list?
3) This works as intended.

I'd like to know the answers for both: C and C++.
Thanks for help!
R



Relevant Pages