Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!boulder!tramp!savage From: savage@tramp.Colorado.EDU (SAVAGE CHARLES L) Newsgroups: comp.lang.c Subject: Re: pointer & struct Message-ID: <6427@boulder.Colorado.EDU> Date: 7 Feb 89 02:05:36 GMT References: <7208@pyr.gatech.EDU> Sender: news@boulder.Colorado.EDU Reply-To: savage@tramp.Colorado.EDU (SAVAGE CHARLES L) Distribution: usa Organization: University of Colorado, Boulder Lines: 37 In article <7208@pyr.gatech.EDU> dvu@pyr.gatech.EDU (Dinh Vu) writes: >The small program below compiled fine, but >it gave core dump when I run it. Would someone give me >some light on this matter. > > #include > > struct abc { > int x; > int y; > }; > > main() > { > struct abc *var; --------------->var = (abc *) malloc ((unsigned) sizeof(struct abc)); > var->x = 5; > var->y = 10; > } > Sombody has probably already fixed this error, but you must alocate memory for the pointer to point too. If not, all the pointer has is a random address, and when you assign a value to the pointer it overwrites some memory in storage that may be used by your source code or may not be yours at all. Savage. D D D