Possible Duplicate:
what's the point in malloc(0)?
what does malloc(0) return?
this code displays "unsuccesful" but if you replace -1 with 0 it wont be NULL. I don't get how you can allocate 0 memory space. I know there's no use but isn't NULL == 0L so it should be == 0 too..
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *ptr;
if((ptr = malloc(-1)) == NULL)
printf("unsuccessful: no memory space was allocated.\n");
else{
printf("successful: memoryspace was allocated. \n");
free(ptr);
}
getch();
return 0;
}