Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!leah!rpi!batcomputer!cornell!rochester!pt.cs.cmu.edu!cadre!pitt!cisunx!ejkst From: ejkst@cisunx.UUCP (Eric J. Kennedy) Newsgroups: comp.sys.amiga Subject: Re: Struggling through the "C" Message-ID: <17491@cisunx.UUCP> Date: 12 Apr 89 02:29:19 GMT References: <2570@ssc-vax.UUCP> <231@nlgvax.UUCP> <6542@cbmvax.UUCP> Reply-To: ejkst@unix.cis.pittsburgh.edu (Eric J. Kennedy) Organization: Univ. of Pittsburgh, Comp & Info Sys Lines: 45 In article <6542@cbmvax.UUCP> kevin@cbmvax.UUCP (Kevin Klop) writes: >Actually, there is a difference between 'a' in the following two >declarations: > >char a[80]; >char *a; [explanation and demonstration deleted] I've always thought that there was another difference besides what you described--one with more important and practical consequences. I've often had trouble with this stuff, being an inexperienced C programmer, so somebody please tell me if this isn't right! I just didn't see anything like this addressed in Kevin's article. It has been my understanding that "char *a;" gives you a pointer, (pointing to some arbitrary place), while "char a[80];" actually allocates 80 bytes of memory, and gives you a pointer to it, one that you can't (or shouldn't) change. Thus, char a[80]; main() { strcpy(a,"hello"); } is okay, while char *a; main() { strcpy(a,"hello"); } will cause real problems, like overwriting your program or another task with the word "hello". You'd have to do a malloc() or AllocMem() or something to have a safe place to put the "hello". So, is this right, or is my feeling of confusion justified? -- Eric Kennedy ejkst@cisunx.UUCP