Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!etive!lfcs!sam From: sam@lfcs.ed.ac.uk (S. Manoharan) Newsgroups: comp.lang.c Subject: Clarification needed on Pointers/Arrays Message-ID: <1436@etive.ed.ac.uk> Date: 20 Feb 89 20:59:17 GMT Sender: news@etive.ed.ac.uk Reply-To: sam@lfcs.ed.ac.uk (S. Manoharan) Organization: Laboratory for the Foundations of Computer Science, Edinburgh U Lines: 57 To clarify my doubts regarding pointers/arrays, I ran the following code. Result: I am more confused. Could someone help me out? I need to reason the likely outcome of /* LINE 1 */ and /* LINE 2 */ main() { static char *a[] = { "123456789", "bull", "fred", "foo" }; /* array of char-pointers */ printf("Entries %d\n",sizeof(a)/sizeof(char *)); foo1(a); foo2(a); } foo1(b) char *b; { int i; printf("Entries %d\n",sizeof(b)/sizeof(char *)); /* LINE 1 */ for ( i = 0; i < 10; ++i ) printf("%d: %c\n",i,b+i); } foo2(b) char *b[]; { int i; /* LINE 2 */ printf("Entries %d\n",sizeof(b)/sizeof(char *)); for ( i = 0; i < 4; ++i ) printf("%d: %s\n",i,b[i]); } -------- Output of the program was: Entries 4 Entries 1 0: ^P <--- Expected ... 1 1: ^Q <--- Expected ... 2 2: ^R <--- Expected ... 3 3: ^S <--- Expected ... 4 4: ^T <--- Expected ... 5 5: ^U <--- Expected ... 6 6: ^V <--- Expected ... 7 7: ^W <--- Expected ... 8 8: ^X <--- Expected ... 9 9: ^Z Entries 1 <--- Expected ... 4 0: 123456789 1: bull 2: fred 3: foo --- sam%uk.ac.edinburgh.lfcs%uk.ac.ucl.cs.nss@net.cs.relay