What is the output of below C program.
int *p = malloc(0);
if(p == NULL)
printf("Couldn't allocate 0 bytes");
printf("allocated 0 bytes");
Couldn't allocate 0 bytes
allocated 0 bytes
compile time error, can't pass 0 to malloc.
Output can be either option 1 or option 2, we can't predict the behavior, as it is implementation dependent of malloc.
int *p = malloc(0);// we can't predict how this will behave, as it is system dependent. some systems will allocate 0 bytes and returns proper address, where as some systems will return null as there is no meaning in allocating 0 bytes.
Back To Top