Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!diamond!jdm5548 From: jdm5548@diamond.tamu.edu (James Darrell McCauley) Newsgroups: comp.lang.c Subject: SIMPLE malloc & pointer question Message-ID: <7206@helios.TAMU.EDU> Date: 7 Aug 90 02:08:58 GMT Sender: usenet@helios.TAMU.EDU Reply-To: jdm5548@diamond.tamu.edu (James Darrell McCauley) Organization: Texas A&M University Agriculture Engineering Department Lines: 37 I have the following code: ---cut here #include #include main() { int *a,*b; b=(int *)malloc( (unsigned) 4*sizeof(int)); b[2]=5; printf("main(): b[2]=%d\n",b[2]); inita(a,b); printf("main(): a[2]=%d\n",a[2]); } inita (a,b) int a[],b[]; { a=(int *)malloc( (unsigned) 4*sizeof(int)); a[2]=3; printf("inita(): a[2]=%d\n",a[2]); printf("inita(): b[2]=%d\n",b[2]); } ---cut here which produces the following output: main(): b[2]=5 inita(): a[2]=3 inita(): b[2]=5 Segmentation fault (core dumped) Could some kind guru point out the error? Thank you very much. --- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - James Darrell McCauley jdm5548@diamond.tamu.edu Dept of Ag. Engineering (409) 845-6484 Texas A&M University, College Station, Texas 77843-2117, USA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -