Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!amdcad!sun!pitstop!sundc!seismo!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.lang.c Subject: Re: pointer allocation Message-ID: <752@auspex.UUCP> Date: 19 Dec 88 18:39:09 GMT References: <8Xf3eSy00UkZ40cVE0@andrew.cmu.edu> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 33 >I am try to allocate a list of integer pointers by the following short >program. But for some reason, after I compiled it and tried to run, >it gave me a Segmentation fault message. I couldn't see what's wrong >there. Could anyone out there give me some guide? > >#include >int *(*B); > >main() >{ > *B = (int *) calloc(18,sizeof(int)); >} The statement "*B = " means "assign the value of the to the object pointed to by 'B'". "B" is implicitly assigned a NULL pointer value by its declaration; therefore, it doesn't point to anything. As such, "assign the value of the to the object pointed to by 'B'" is a meaningless command, since there *is* no object pointed to by "B". The RT PC presumably catches attempts to dereference NULL pointers, as do several other C implementations. Why did you not just do ... int *B; main() { B = (int *) calloc(18, sizeof(int)); }