Below code doesn't give any allocation error , however the counting ends at about 16970 with memory allocation error and system halted ,I use Turbo C++ 3.0 IDE ,Windows XP sp3 , all partitions : NTFS ,PC : Dell 1545 with 2 GB ram installed .
#include <stdio.h>
#include <stdlib.h>
long counter=0;
int main(int argc, char *argv[])
{
char* array=(char*) malloc (1024*1024*10);
if (array==NULL)
{
/* allocation error */
return 1;
}
for (counter=0 ; counter<10000000;counter++)
array[counter] = 1; // trying to fill the array with one's
free (array);
return 0;
}