Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!uwvax!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: arrays (was Another silly question) Message-ID: <17762@mimsy.UUCP> Date: 26 May 89 11:08:23 GMT References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> <96@elf115.uu.net> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 22 In article <96@elf115.uu.net> rec@elf115.uu.net (Roger Critchlow) writes: >I think of C arrays as syntactic sugar for initialized pointers. >Thus > > char foo[] = "I am an anonymous char *"; > >is an abbreviation for > > register char *const foo = "I am an anonymous char *"; The only problem with this is that it is wrong. Given the first declaration, sizeof(foo) is 25. Given the second, sizeof(foo) is typically something like 4. This is only the most obvious of many differences. An array is an array, and a pointer is a pointer, and the twain meet only in rvalue contexts, where an object of type `array N of T' is converted to one of type `pointer to T' whose value is &array[0]. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris