Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!caen!uwm.edu!linac!att!ucbvax!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Array initialization question Message-ID: <13193@dog.ee.lbl.gov> Date: 14 May 91 20:43:52 GMT References: <43075@netnews.upenn.edu> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Distribution: usa Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 28 X-Local-Date: Tue, 14 May 91 13:43:52 PDT In article <43075@netnews.upenn.edu> carey@eniac.seas.upenn.edu (Robert Carey) writes: > static char foo[2][5]={"12345", "67890"}; The ANSI C standard (X3.159-1989) explicitly says that if you use a string literal as an initializer for a character array and you have specified the size of the array and the string literal exactly fills the array when the trailing '\0' character is dropped, that is what you get. Thus, this creates two adjacent blocks of 5 `char's and sets them to: '1' '2' '3' '4' '5' '6' '7' '8' '9' '0' (Some argued that this was a misfeature, but alternative proposals such as `\c' for suppressing trailing NULs in string literals were eventually rejected. Some find the whole thing incomprehensible: if you wanted this result you could have used static char foo[2][5] = { {'1', '2', '3', '4', '5'}, {'6', '7', '8', '9', '0'}, }; I tend toward the latter camp; if a mechanism for omitting the trailing NUL in string literals is to be required, I tend toward the former camp.) -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov