Date: Sun, 26 Apr 1998 19:13:48 +0300 (IDT) From: Eli Zaretskii To: leger_v AT bluewin DOT ch cc: djgpp AT delorie DOT com Subject: Re: Problem with malloc() and integers In-Reply-To: <35433669.5A75@bluewin.ch> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Sun, 26 Apr 1998 leger_v AT bluewin DOT ch wrote: > void main(void) > { int i,j; > unsigned long *test[10]; > > for(i=0;i<10;i++) > test[i]=(unsigned long *)malloc(64000); > > for(i=0;i<10;i++) > for(j=0;j<64000;j++) > test[i][j]=10; > } > And this program crashes on my computer. Of course, it will crash! "malloc(64000)" allocates 64K BYTES, not 64K LONGS, so you are referencing in the loop more than you have allocated! You need to say "malloc(64000*sizeof(long))" to get what you want without crashing.