SIMPLE malloc & pointer question
James Darrell McCauley
jdm5548 at diamond.tamu.edu
Tue Aug 7 12:08:58 AEST 1990
I have the following code:
---cut here
#include<stdio.h>
#include<malloc.h>
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 at diamond.tamu.edu
Dept of Ag. Engineering (409) 845-6484
Texas A&M University, College Station, Texas 77843-2117, USA
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
More information about the Comp.lang.c
mailing list