0

Why does

int *p; 
p= (int *) malloc(0);
printf ("%p", p); 

print an address? Because logically its a 0 bytes of memory, so what is that base address meaning to? (I mean the address stored in p).

*Kindly any well known dev in this topic, pls do reply to this query.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • 3
    Because it can? The only thing you can do with that pointer is pass it to `free()` or `realloc()`, though. Can't dereference it. – Shawn Mar 22 '21 at 07:51
  • Rather because someone without common sense designed the API, so it allows malloc to either return NULL or an address... Don't mistake the C standard lib for something carefully designed after some sort of rationale. – Lundin Mar 22 '21 at 11:34

0 Answers0